How to make a Node.js application run permanently?

Sometimes, we want to make a Node.js application run permanently.

In this article, we’ll look at how to make a Node.js application run permanently.

How to make a Node.js application run permanently?

To make a Node.js application run permanently, we can use the forever package.

We install it globally by running

sudo npm install -g forever

Then we can start our app with it with

forever server.js

We can also run it as a service with

forever start server.js

We can restricts restarts to 5 times when it crashes or stop unexpectedly with

forever -m5 server.js

We can stop a process with

forever stop 0

where 0 is the process ID.

And we can restart a process with

forever restart 0

where 0 is the process ID.

Conclusion

To make a Node.js application run permanently, we can use the forever package.