Hi i have js file like below
var myfun = function(){ return "string from function." }
i Need command line like below
node myfile.js myfun()
output : string from function.
how to achieve this?
Hi i have js file like below
var myfun = function(){ return "string from function." }
i Need command line like below
node myfile.js myfun()
output : string from function.
how to achieve this?
One option is to use make-runnable you will need just to add require('make-runnable');
at the end of the file and you can call it like node myfile.js myfun
.
Or you can change myfile.js
contents to:
module.exports.myFun = function () { return "string from function." };
and call it from the command line using this command:
node -e "console.log(require('./myfile.js').myFun())"
or even simpler, with this one:
node -p "require('./myfile.js').myFun()"