25

I am having hard time understanding what is forever in nodejs.

Can someone explain what is forever in simplest way that i can understand and what is the purpose of it

Tushar
  • 85,780
  • 21
  • 159
  • 179
Agent69
  • 648
  • 1
  • 8
  • 16
  • 4
    `forever` keeps the node server _alive_. When the node server is stopped becaluse of some error, exception, etc. `forever` automatically restarts it. `A simple CLI tool for ensuring that a given node script runs continuously (i.e. forever)` Read more https://www.npmjs.com/package/forever – Tushar Oct 05 '15 at 07:29
  • @Tushar you might want to put this as an answer which should be the accepted one – user2720864 Oct 05 '15 at 09:05

3 Answers3

29

forever is a node.js package that is used to keep the server alive even when the server crash/stops. When the node server is stopped because of some error, exception, etc. forever automatically restarts it

From the npmjs https://www.npmjs.com/package/forever

A simple CLI tool for ensuring that a given node script runs continuously (i.e. forever)

Forever can be used as

forever start app.js

It provides many useful functions which you can see in the link above.

Directly quoting from http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever/

The purpose of Forever is to keep a child process (such as your node.js web server) running continuously and automatically restart it when it exits unexpectedly.

Tushar
  • 85,780
  • 21
  • 159
  • 179
  • If you are interested in `running` forever as service https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/ – Tushar Oct 05 '15 at 09:13
  • Forever tagged [questions](http://stackoverflow.com/questions/tagged/forever) on SO – Tushar Oct 05 '15 at 09:15
4

Forever basically allows you to run your nodejs application as a process.

Without forever you might type npm start or node index.js to start your application and it will run in your terminal session.

With forever, you can start it off and still have access to your terminal session/close it.

Matt The Ninja
  • 2,641
  • 4
  • 28
  • 58
  • 7
    NO! `forever` keeps the node server _alive_. When the node server is stopped becaluse of some error, exception, etc. `forever` automatically restarts it. – Tushar Oct 05 '15 at 07:29
-1

You can even use the nohup command it simply ignores the hang up signal.

node index.js && nohup -& (to run as a background process - no hiccup)
vvvvv
  • 25,404
  • 19
  • 49
  • 81