If I construct a function or list of commands that are stored in a string variable, is there a way I can execute them in node and retain what is returned in another variable? i.e.
var result = executeMyCoolStringCommands(myStringVariableWithCommands);
option -e
will let you run arbitary text as node.js source code:
node -e "console.log(JSON.stringify({}))"
Sure, we all know evils of using eval
, however the npm module eval avoids its use yet executes a string
var _eval = require('eval')
var res = _eval('var x = 123; exports.x = x')
console.log("here is res ", res);
which outputs :
here is res { x: 123 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With