javascript - Run two scripts simultaneously - Stack Overflow

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744736017a4590750.html

相关推荐

  • javascript - Run two scripts simultaneously - Stack Overflow

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

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信