is it possible to parse a node js file and run part of the code from inside of another node js file?
I have a node.js file that I am trying to parse from inside another node.js script. I don't control the contents of the file, but it is valid node.js and it always has a function inside of the code called: getParameterDefinitions
Here is a file I am trying to parse: https://github.com/jscad/OpenJSCAD.org/blob/master/examples/gear.jscad
Specifically I want the JSON array returned from getParameterDefinitions as a variable in my code.
Here is the code I have currently:
const fs = require('fs')
inputFile = 'gear.jscad'
let src = fs.readFileSync(inputFile, 'UTF8')
console.log(src)
params = Parse(src,'getParameterDefinitions') //how to write this line?
How can I have node parse the javascript and run the function to get me back the results into the params variable.
eval.function getValues(code) { eval(code); return getParameterDefinitions(); }. Then call it like:var params = getValues(src);. BUT only if you're suresrcdoesn't contain any harmful code.eval(code)itsevil(code). ;) BTW, avoidevalat all costs especially innode.