Auto start Next.js with supervisor
I want to start Next.js development server on my computer when it starts. Usually, this is done using pm2, I wanted to do it with supervisors.
Install supervisor with command
1 |
apt install -y supervisor |
Create file
1 |
vi /etc/supervisor/conf.d/nextjs-todo.conf |
My Next.js application is located in the directory /mnt/data/sites/learn/nextjs/todo, so I used the following configuration
1 2 3 4 5 6 7 8 |
[program:nextjs-todo] priority=200 directory=/mnt/data/sites/learn/nextjs/todo command=npm run dev user=boby autorestart=true autostart=true redirect_stderr=true |
In the file change “user=boby” to whatever username you want the application to run as.
To start the application, run
1 |
supervisorctl reload |
To see the application status, run
1 2 3 |
boby@sok-01:~$ sudo supervisorctl status nextjs-todo RUNNING pid 32604, uptime 0:07:49 boby@sok-01:~$ |
Back to supervisord