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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744736017a4590750.html
评论列表(0条)