Mobile Man
Mobile Man

Reputation: 321

How do invoke script with another node script?

I have an node app that runs as a cron job every few seconds:

   var CronJob = require('cron').CronJob;
   new CronJob('*/5 * * * * *', function(){
       console.log('Here invoke a script called requestdata');
   }, null, true, "America/Los_Angeles");

and I just want to call a script without invoking functions on it. So its not

          requestdata.foo();

but just call requestdata in same directory. how is this done? If it was on command line I would just do:

     node requestdata

but how do I do this inside another script?

Upvotes: 3

Views: 4478

Answers (2)

Rob Little
Rob Little

Reputation: 260

This solution also shows how to pass parameters to the "request data.js" script

var cp = require('child_process');
cp.fork(__dirname + '/request data.js',[array,of,string,prams]);

Upvotes: 2

yoelp
yoelp

Reputation: 1631

Use child_process, like so

var cp = require('child_process');
cp.fork(__dirname + '/request data.js');

See http://nodejs.org/api/child_process.html

Upvotes: 5

Related Questions