admin管理员组

文章数量:1391951

I created a web application in azure to host my application js node. (Azure web application)

In my project I have an api in express that is in the app.js, however in the same project I have another file which is a cronjob.

In my package.json I have the following configuration for script:

"scripts": {
    "start": "node app.js"
  }

When deploying through github, the api that is in the app.js works perfectly.

My question: How do I run cronjob.js simultaneously with app.js?

I created a web application in azure to host my application js node. (Azure web application)

In my project I have an api in express that is in the app.js, however in the same project I have another file which is a cronjob.

In my package.json I have the following configuration for script:

"scripts": {
    "start": "node app.js"
  }

When deploying through github, the api that is in the app.js works perfectly.

My question: How do I run cronjob.js simultaneously with app.js?

Share Improve this question asked Oct 27, 2017 at 4:55 GansonicGansonic 3477 silver badges15 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

You can start multiple application by using "pm2" node_module.

After installing pm2 module you can start your application by using the following mand in terminal.

pm2 start app.js && pm2 start cronjob.js

You may also use forever node module.

If the only requirement is that, I think there is no need to use another tool. Simply, you can achieve this with a single ampersand &.

"scripts": {
  "start": "node app.js & node cronjob.js"
}

Another option to running multiple scripts simultaneously is npm-run-all.

Install with:

npm install --save npm-run-all

Then setup your "scripts" section in your package.json like so:

"scripts": {
  "app": "node app.js",
  "cronjob": "node cronjob.js",
  "start": "npm-run-all --parallel app cronjob"
}

And start with npm start as usual.

本文标签: javascriptRun two scripts simultaneouslyStack Overflow