How to run/work with production mode for NodeJS Apps?

Category: NodeJS

You should run your NodeJS App in production mode only when you are sure that your App will run in a stable way. This you can easily ensure by first running your App in development mode. To run your app in development mode or to install requisite npm modules, please refer to the following link : https://n99panel.com/ufaq/how-to-run-work-with-development-mode-for-nodejs-apps  .

Now to run the App in production mode,

  1. Login into the N99panel
  2. Go to under Dashboard -> Node Apps -> Link a Node App
  3. Select the VHost (website) mentioned along with the user and the port range.
  4. Enter the ‘App Web path’ . This would be like /app1 or /app2 or it can even be the website root i.e. /
  5. Enter the ‘App Port’ . The port on which your App creates the server. The value for the App Port should be in the range of 40000 to 50000
  6. Select the ‘App Mode’. This should be ‘Production (node)’ or ‘Production (npm start)’
  7. Now enter the reference to the App file in the  ‘Prod. filesystem Path’ field. Your app should be in /home/{username}/node_apps . Ideally a separate folder so that you can run multiple apps without disturbing each other’s dependencies. Our app would typically be placed in a folder with /home/{username}/node_apps  .  Depending upon the ‘App Mode’, following points apply
    1. Now if our ‘App Mode’ was ‘Production (node)’, then this path should lead to a file. if my app files is app.js , the value entered in  ‘Prod. filesystem Path’ will be app1/app.js , if app1 was the folder containing the app.
    2. But if our ‘App Mode’ was ‘Production (npm start)’, then this path show lead to a folder where your package.json resides. The example value for ‘Prod. filesystem Path’ can be app1 , implying the full path to be /home/{username}/node_apps/app1 .
  8. Next, select the ‘Prod. Node Version’ . The available versions are 10, 12, 14, 16, 18, 20
  9. Next if you wish to run a Redis instance alongside your App, enable the same by clicking the checkbox against ‘Redis (Prod. mode only)’
  10. And finally click ‘Submit’

Please note : Only one app can run on a given VHost/website and App Web path’ . If you were earlier running an app on development mode at that path, unlink that App first from within Dashboard -> Node Apps -> App : Remove Linking , and then link the same app again in production mode.

Before running your app in production mode, kindly test your app in development mode first. Only after extensive testing, you may then use production mode.

To manage the App process, you can do the same from within Node Apps -> App : Manage App State