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

apt install -y supervisor

Create file

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

[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

supervisorctl reload

To see the application status, run

boby@sok-01:~$ sudo supervisorctl status
nextjs-todo                      RUNNING   pid 32604, uptime 0:07:49
boby@sok-01:~$ 

Back to supervisord

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *