I am trying to deploy a simple NodeJS app to Azure App Service, I would like the app to run using PM2 with the option to configure multiple processes using PM2
I tried few options:
Option 1: with "start": "node index.js"
in package.json, the app serves requests but does not run on PM2. No processes were running when I run PM2 list
command in app service ssh console.
Although Azure docs indicate that the container automatically starts the app with PM2 when index.js file is in the root folder, this did not happen.
Option 2: with "start": "pm2 start --no-daemon index.js"
in package.json, the app was started with PM2, only 1 process was running (confirmed this by running PM2 list
command in app service ssh console).
How do I run multiple processes using pm2 ? on Azure App Service
Option 3: With the intention of running multiple processes, In addition to "start": "node index.js"
in package.json, I also created a ecosystem.config file using pm2 init
. I get this error
ERROR - Container test didn't respond to HTTP pings on port: 8080, failing site start
ecosystem.config file:
module.exports = {
apps : [{
script: 'index.js',
watch: '.'
}, {
script: './service-worker/',
watch: ['./service-worker']
}],
deploy : {
production : {
user : 'SSH_USERNAME',
host : 'SSH_HOSTMACHINE',
ref : 'origin/master',
repo : 'GIT_REPOSITORY',
path : 'DESTINATION_PATH',
'pre-deploy-local': '',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': ''
}
}
};
Package.JSON
{
"name": "app-service-hello-world",
"description": "Simple Hello World Node.js sample for Azure App Service",
"version": "0.0.1",
"private": true,
"license": "MIT",
"author": "Microsoft",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"dotenv": "^10.0.0"
}
}
Index.js
const http = require("http");
const server = http.createServer((request, response) => {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Hello World!");
});
const port = 8080;
server.listen(port);