How to Run a Npm Start Script with Pm2

Are you looking for a way to run npm start scripts with Pm2? Or how to to do so while also using the options commands with it as well?
In this article, we will go through some examples that will help you achieve this. Check out each of the examples below!.
Npm Start Script
To run the npm start script with Pm2, you can use the following command (make sure you call the command from inside your project folder):
$ pm2 start npm -- start
And you should see a similar output in your command prompt:
[PM2] Starting /usr/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
npm      │ 0  │ fork │ 3524 │ online │ 0       │ 0s     │ 4.0 KB      │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
Npm Start Script With the App Name Option
Here is an example of running an npm start script with the --name Pm2 option to name your application.
Here is the command (replace the yellow text with the name of your app):
$ pm2 start --name=APP_NAME npm -- start
And you should see a similar output in your command prompt:
[PM2] Starting /usr/bin/npm in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
APP_NAME │ 0  │ fork │ 3524 │ online │ 0       │ 0s     │ 4.0 KB      │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
Npm Start Script With Multiple Options
In the last example, we will cover how to run an npm script with multiple options.
Here is the command (replace the yellow text with your app name):
$ pm2 start --name=APP_NAME --no-autorestart npm -- start
You should see the same output as the previous examples.
Conclusion
Hopefully, this article helped get your npm application up and run using the Pm2 process manager.
Thanks for reading and happy coding!