Managing Nodejs Apps with Forever

Source: Internet
Author: User
Tags app service

What is ForeverForever can be seen as a Nodejs daemon that can start, stop, and restart our app. The official note is that the following code is copied: A Simple CLI Tool forEnsuring that a given script runs continuously (i.e. forever).
//a simple command-line tool for continuing (or forever) running a given scriptGitHub Address: Https://github.com/nodejitsu/forever

Forever UseThe purpose of forever is to help us better manage our Node app service, essentially creating a child process for the node app under the forever process. For example, if you have an express-based or some other application then it will be convenient for you to update and operate your service and ensure that your service will continue to operate. The better thing is that every time you change a file, it can help you automatically restart the service without requiring a manual restart. Install the Forever code as follows://Remember to add-g,forever required to install in the Global environment
sudo npm install forever-g
Forever instructions for use

Start the relevant code as follows://1. Simple Start-up
Forever Start App.js

//2. Specify forever information output file, of course, it will be put to ~/.forever/forever.log
Forever Start-l Forever.log App.js

//3. Specify the log information and error log output files in the app.js.
//- o is the Console.log output information,-e is the Console.error output information
Forever Start-o out.log-e Err.log app.js

//4. Append the log, forever default is not to overwrite the last boot log,
//so if the second boot does not add-a, it will not let the run
Forever Start-l forever.log-a App.js

//5. Listen for all file changes under the current folder
Forever Start-w App.js

File change monitoring and automatic restart code are as follows://1. Listen for all file changes under the current folder (not recommended)
Forever Start-w App.js shows all running service codes as follows: Forever list

The stop operation code is as follows://1. Stop all running node apps
Forever StopAll

//2. Stop one of the node apps
Forever Stop App.js
//Of course you can do that .
//Forever list to find the corresponding ID, and then:
Forever Stop [ID]

Restarting the restart operation is consistent with the stop operation. The code is as follows://1. Start All
Forever Restartall Development and on-line recommended configuration codes are as follows://under development environment
Node_env=development Forever start-l forever.log-e err.log-a app.js
//in the online environment
Node_env=production Forever start-l ~/.forever/forever.log-e ~/.forever/err.log-w-a app.js plus Node_ Env in order for App.js to identify what environment is currently used. Without it, you might not know?

some points of attention

It is possible that you need to use crontab (timed tasks) under UNIX to be aware of configuring environment variables. The code is as follows: Shell=/bin/sh
Path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Managing Nodejs Apps with Forever

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.