Issue
I created a module that exports a function. Im my express server, im trying to send this function to the front end, but it is coming blank.
Im using Axios API to get the data in the front end.
Im very newb with NodeJs and Express.
This is my code:
// Back End
function myFunction(){
console.log("did work");
}
app.get("/getData", (req, res) => {
res.json({
randomData: randomData,
myFunction: myFunction
});
res.end();
});
// Front End
axios.get("/getData").then(e=>{
console.log(e.data);
});
This is the data ta i get in the front end:
Solution
JSON does not support functions.
If you want to send code, you would have to convert it to a string.
Answered By – Luís Henrique de Almeida
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0