How to do it...

Let's follow these steps to implement Forever as a process manager for our Express application:

  1. First, let's make a test route that will cause an artificial crash in our application:
app.get('/crash', function(req, res) {
this.does.not.exist;
process.exit(1);
});
  1. To run our application with Forever, we will stop our web server and restart it using Forever instead. We will also provide configuration details for how and where error logs should be saved:
FOREVER_ROOT=~/my-express-project forever start -e error.log ./bin/www
  1. Now, when we visit the /crash route of our web application, our process will be terminated, but Forever will automatically restart it for us. We can test this by visiting /posts afterward to verify that the server has been restarted for us automatically.
  2. When we want to stop our Forever process, we can use stopall to kill all watched processes:
forever stopall
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.244.137