%%
date:: [[2023-05-13]]
parent::
%%
# [[PM2]]
PM2 is a production process manager for [[NodeJS]] apps that lets you start multiple apps and not need to tie up your terminal with any of them (kind of like [[Linux#Leave a process running after you disconnect|screen]]. It also includes a load balancer for the apps you're running. [^npm]
## Usage
### Start an app
```
pm2 start app.js
```
### List all running apps
```
pm2 list
```
From there, you can also get the name of any of the running apps.
### Restart app
```
pm2 restart name
```
Get `name` from [[PM2#List all running apps]].
### Update environment variables
Restarting an app doesn't necessarily make it update environment variables. To do that, run this instead:
```
pm2 restart name --update-env
```
### Save the current state
```
pm2 save
```
This command remembers all the apps that are currently running.
### Load a saved state
```
pm2 resurrect
```
This command starts all the apps that were running in the state that you saved.
### Restart currently running apps on boot
```
pm2 startup
```
This loads the saved state, including all running apps, in case the server restarts.
[^npm]: pm2. (2023). *pm2 - npm*. Retrieved from https://www.npmjs.com/package/pm2