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 badges3 Answers
Reset to default 6You 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
版权声明:本文标题:javascript - Run two scripts simultaneously - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744736017a2622332.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论