0

I am using forever-monitor nom module to run sample.js script forever. I am trying to send arguments from index.js(where I am using below code to initialize forever-monitor module) to target script i.e. sample.js. There is an option for this i.e. args however, when I am trying to send arguments with this option and access that argument in sample.js file it returns undefined. How can I pass argument and access it in target script using forever-monitor?

let forever = require('forever-monitor');

let child = new (forever.Monitor)(‘sample.js', {
    'silent': false,
    'args': ['foo']
});

child.on('exit', () => {
    console.log(‘sample.js has exited.’);
});

child.start();

UPDATE

Since I am passing arguments from one javascript file to another not from command line for that reason it is not a duplicate.

Om3ga
  • 30,465
  • 43
  • 141
  • 221

1 Answers1

0

The problem lies in your sample.js. To get console arguments, you need to use process.argv:

console.log(process.argv[1]); //Should echo 'foo'
Blue
  • 22,608
  • 7
  • 62
  • 92