Running Production Build Nodejs Apps on App Service Linux

1 minute read | By Toan Nguyen

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

  1. In the Azure Portal, go to Configuration.
  2. Select General and locate the Startup Command box.
  3. If all of the items in the build directory are in wwwroot, change the path to /home/site/wwwroot.
         pm2 serve /home/site/wwwroot/build --no-daemon
    
  4. If the content is under dist, make sure to use the following.
        pm2 serve /home/site/wwwroot/dist --no-daemon
    
  5. Press Save.

Process File

  1. Create a process.json or process.yml and place it in /home/site/wwwroot.
  2. In this example, I’m using a process.json file and my files are under the build directory. Make sure to change this to dist if your framework is outputing to the dist directory.

         {
         "script": "serve",
         "env": {
             "PM2_SERVE_PATH": './build'
         }
         "args": '--no-daemon'
         }
    
  3. In the Azure Portal, go to Configuration.
  4. Select General and locate the Startup Command box and enter process.json.
  5. Press Save.