Home > Net >  How to pass parameter when executing a node.js script?
How to pass parameter when executing a node.js script?

Time:09-30

I wish to send some parameters when running a node script, using for instance

node myscript.js

from the terminal, so it can be read as below:

const fs = require('fs');

console.log(myParameter);

CodePudding user response:

You just need to call as many arguments as you want, like:

node myscript.js arg1 arg2 arg3

And you recover them like:

console.log(process.argv[2]);
  • Related