Running Production Build Nodejs Apps on App Service Linux
When you create production build for your React, Angular, other Node framework the files will either be placed in a build
or dist
directory depending on the framework. App Service on Linux uses Oryx to detect, build, and start your application. For more information about how this is done, please go to the Oryx GitHub page for more info. In order to serve the built content, you can perform either of the following.
PM2 Serve
- In the Azure Portal, go to Configuration.
- Select General and locate the Startup Command box.
- If all of the items in the
build
directory are inwwwroot
, change the path to/home/site/wwwroot
.pm2 serve /home/site/wwwroot/build --no-daemon
- If the content is under
dist
, make sure to use the following.pm2 serve /home/site/wwwroot/dist --no-daemon
- Press Save.
Process File
- Create a process.json or process.yml and place it in
/home/site/wwwroot
. -
In this example, I’m using a process.json file and my files are under the
build
directory. Make sure to change this todist
if your framework is outputing to thedist
directory.{ "script": "serve", "env": { "PM2_SERVE_PATH": './build' } "args": '--no-daemon' }
- In the Azure Portal, go to Configuration.
- Select General and locate the Startup Command box and enter
process.json
. - Press Save.