I would like to pass a javascript function in Node.js as a parameter in a URL from one server to another. I am using axios npm package to send the data, here's a sample of the code:
let f = function(){
return "Returned Value Here";
}
axios({url: '/', method: 'POST', data: {something: "foo", bar: f}})
.then((response)=>{console.log(response)})
.catch((reason){console.log(reason)})
Acccording to other questions it was suggested that I use eval() javascript function to evaluate the code but this causes a problem. Firstly I would like to pass the function on the receiver side and NOT evaluate it. And even if I evaluate to get a function it would be a named function (I want to pass an anonymous function) that canNOT be referenced for example let bar = eval('function baz(){console.log("Test");}') bar is not a reference of the function (bar is undefined) and also if you use typeof baz() the returned value is STRING. So how can I pass a function in a URL? Keep in mind POST requests send data as binary
via omarwaleed
No comments:
Post a Comment