I make my scripts on windows then put them on my ubuntu server. This is my first time trying to pass args into the script on start up.
It works on windows I run
node file.js --variable=value
Then in my code I grab it with
const passedIn = require(argv.variable);
I cant figure out how to make this work with pm2.
I have been trying
pm2 start file.js --name myScript --node-args="value"
I didnt expect this to work. What do I need to call to access my passed in arg correctly from the code instead of argv.variable
? and can I still do something like
--node-args="variable=value"
2
Answers
I was able to do it like this
pm2 start script.js --name myScript -- -v=value
and access it in code with
var argv = require('minimist')(process.argv.slice(2));
console.log(argv.v);
it only seemed to allow 1 letter variables.
Try this:
Alternatively, add
--
, followed by your script args:Details: https://futurestud.io/tutorials/pm2-how-to-start-your-app-with-node-js-v8-arguments