[Server Running] [Node.js, PM2] Using PM2 To Keep Your Node Apps Alive
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
Install:
$ npm install pm2 -g
Before Start:
PM2 can generate and configure a startup script to keep PM2 and your processes alive at every server restart.
$ pm2 startup
# auto-detect platform
$ pm2 startup [platform]
# render startup-script for a specific platform, the [platform] could be one of:
# ubuntu|centos|redhat|gentoo|systemd|darwin|amazon
Start:
$ pm2 start bin/www /* meds example */

This has the same effect as:
$ node bin/www
run the app, but on windows, it just keep it run once, once you refresh the page, the app die. [PROBLEM]
If it works as expected, when you kill the process:
kill - <pid>
The pm2 will detect that our app is crashed, so it will start a new pid to run the app.
[Notice:] On Linux, PM2 will grap the root, run as root, but in genral, we don't want to use root. So we usually create a user to use PM2.
pm2 startup on liunx:

Change the user:

test script:

More information:
https://egghead.io/lessons/node-js-using-pm2-to-keep-your-node-apps-alive
https://github.com/Unitech/pm2
[Server Running] [Node.js, PM2] Using PM2 To Keep Your Node Apps Alive的更多相关文章
- The Node.js Event Loop, Timers, and process.nextTick() Node.js事件循环,定时器和process.nextTick()
个人翻译 原文:https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/ The Node.js Event Loop, Ti ...
- 深入浅出Node.js(一):什么是Node.js
Node.js从2009年诞生至今,已经发展了两年有余,其成长的速度有目共睹.从在github的访问量超过Rails,到去年底Node.jsS创始人Ryan Dalh加盟Joyent获得企业资助,再到 ...
- 深入浅出Node.js(一):什么是Node.js(转贴)
以下内容转自:http://www.infoq.com/cn/articles/what-is-nodejs/ 作者:崔康 [编者按]:Node.js从2009年诞生至今,已经发展了两年有余,其成长的 ...
- Node.js学习笔记(1):Node.js快速开始
Node.js学习笔记(1):Node.js快速开始 Node.js的安装 下载 官方网址:https://nodejs.org/en/ 说明: 在Windows上安装时务必选择全部组件,包括勾选Ad ...
- node.js系列(实例):原生node.js+formidable模块实现简单的文件上传
/** * 原生node.js结合formidable模块实现图片上传改名 * @Author:Ghost * @Date:2016/07/15 * @description: * 1.引入模块htt ...
- node.js系列(实例):原生node.js实现接收前台post请求提交数据
前台界面: 前台代码: <form class="form-horizontal" method="post" action="http:127 ...
- node.js零基础详细教程(4):node.js事件机制、node异步IO操作
第四章 建议学习时间3小时 课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑. ...
- node.js零基础详细教程(7):node.js操作mongodb,及操作方法的封装
第七章 建议学习时间4小时 课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑. ...
- Node.js实战项目学习系列(1) 初识Node.js
前言 一直想好好学习node.js都是半途而废的状态,这次沉下心来,想好好的学习下node.js.打算写一个系列的文章大概10几篇文章,会一直以实际案例作为贯穿的学习. 什么是node Node.js ...
- 【Nodejs】【node.js 安装 和 配置Sublime Text的Node.js】
[一] [安装nodejs] 第一步:下载安装文件: https://nodejs.org/en/download/ 第二步:安装nodejs 下载完成之后,双击"node-v6.10.1- ...
随机推荐
- UVa 1605 (构造) Building for UN
题意: 有n个国家,要设计一栋长方体的大楼,使得每个单位方格都属于其中一个国家,而且每个国家都要和其他国家相邻. 分析: 紫书上有一种很巧妙的构造方法: 一共有2层,每层n×n.一层是每行一个国家,另 ...
- [swustoj 917] K-lucky-number
K-lucky-number(0917) 问题描述 K-lucky-number is defined as add up the number of each bit is a multiple o ...
- 【MySql存储过程】DATE_ADD用法
定义和用法 DATE_ADD() 函数向日期添加指定的时间间隔. 语法 DATE_ADD(date,INTERVAL expr type) date 参数是合法的日期表达式.expr 参数是您希望添加 ...
- WCF 服务调用RFC 出现异常
我在VS2010的WCF项目用connecter 3.0 调用 RFC 运行到 IDestinationConfiguration ID = new SAPConfig(); ...
- idea开发工具中你可能不知道的却又比较好用的快捷键
Alt+insert :生成代码 较为常用的是 1.普通Class中生成get set 方法 .生成构造函数.生成spring注入.重写对象的equal.toString.hashcode方法 2.如 ...
- Can not perform pod install under el capitan (15A279b)
这个问题在stackoverflow上面有过讨论: Can not perform pod install under el capitan (15A279b) 被采纳的答案为:sudo gem in ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.4.4
(1). There is a natural isomorphism between the spaces $\scrH\otimes \scrH^*$ and $\scrL(\scrH,\scrK ...
- 【打包成exe安装包文件发布你的程序】使用QT联系人管理系统的例子
[前言]在 QT数据库使用案列[联系人]-- 使用sqlite和QStringListModel 中,我们写了这个程序,如何将它打包成安装文件发给其他小伙伴呢? 我们使用 nsis-2.46-setu ...
- iOS开发UI篇—实现一个私人通讯录小应用【转】
转一篇学习segue不错的教程 一.该部分主要完成内容 1.界面搭建 2.功能说明 (1).只有当账号和密码输入框都有值的时候,登录按钮才能交互 (2). ...
- sys.argv[]基本用法
#python 3.4.2 #windows系统下可以在CMD下执行 python test.py 第一参数 第2个参数 #空格分隔每个参数,sys.argv[]是用来获取命令行参数的 #引用必要的包 ...