A javascript file foo.js has the following content:
function foo(param){
    console.log('foo called with params');
    console.log(param);
}
module.exports.foo = foo;
How can I call this function from within a package.json script?
"scripts": {
        "foo": "node foo.js foo(1)", 
    },
Just returns
node foo.js foo(1)
I.e., the function is not invoked.
Your command node foo.js foo(1) does not run even if you don't put it inside an npm script:
process.argv[2] to capture args from the commandWhich means that your foo.js script should look like:
console.log('generateI18 is with param');
console.log(process.argv[2]);
(no need to export anything)
And you can execute it as:
node foo.js 1
You can then add it to your npm scripts:
"scripts": {
    "foo": "node foo.js 1", 
},
and run it:
npm run foo
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