In this lesson, you will learn how to configure node apps using pm2 and a json config file.

Let's say there are tow node apps: app1, app2.

What we want to do is create a json fie as config file for pm2.

pm2.config.json:

{
"apps": [{
"name": "App1",
"script": "app1/server.js"
},{
"name": "App2",
"script": "app2/server.js"
}]
}

app1/server.js:

var http = require("http");
var server = http.createServer(function(request, response){
response.writeHead('200', {"Content-Type": "text/plain"});
response.end("Hello from app1");
});
server.listen(3000);
console.log("Listen on port 3000");

app2/server.js:

var http = require("http");
var server = http.createServer(function(request, response){
response.writeHead('200', {"Content-Type": "text/plain"});
response.end("Hello from app2");
});
server.listen(3001);
console.log("Listen on port 3001");

Usage:

pm2 start pm2.comfing.json

[Whole Web, Node.js, PM2] Configuring PM2 for Node applications的更多相关文章

  1. [Node.js] 01 - How to learn node.js

    基本概念 链接:https://www.zhihu.com/question/47244505/answer/105026648 链接:How to decide when to use Node.j ...

  2. node.js day01学习笔记:认识node.js

    Node.js(JavaScript,everywhere) 1.Node.js 介绍 1.1. 为什么要学习Node.js 企业需求 + 具有服务端开发经验更好 + front-end + back ...

  3. node.js学习(二)--Node.js控制台(REPL)&&Node.js的基础和语法

    1.1.2 Node.js控制台(REPL) Node.js也有自己的虚拟的运行环境:REPL. 我们可以使用它来执行任何的Node.js或者javascript代码.还可以引入模块和使用文件系统. ...

  4. Node.js学习笔记(五) --- 使用Node.js搭建Web服务器

    1. Node.js 创建的第一个应用 1.引入http模块 var http = require("http"); 2. 创建服务器接下来我们使用 http.createServ ...

  5. Node.js 学习(五)Node.js 事件循环

    Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...

  6. [Node.js] Add Logging to a Node.js Application using Winston

    Winston is a popular logging library for NodeJS which allows you to customise the output, as well as ...

  7. 创业笔记-Node.js入门之JavaScript与Node.js

    JavaScript与Node.js JavaScript与你 抛开技术,我们先来聊聊你以及你和JavaScript的关系.本章的主要目的是想让你看看,对你而言是否有必要继续阅读后续章节的内容. 如果 ...

  8. 前端(Node.js)(3)-- Node.js实战项目开发:“技术问答”

    1.Web 与 Node.js 相关技术介绍 1.1.Web应用的基本组件 web应用的三大部分 brower(GUI)<==>webserver(business logic.data ...

  9. 前端(Node.js)(2)-- Node.js开发环境配置

    1.开发环境介绍 1.MEAN Stack 什么是全栈? 负责界面和UI的设计师.负责移动端应用开发的安卓IOS开发工程师.负责服务器端开发的后端程序员.负责数据库开发和管理的数据库工程师.负责服务器 ...

随机推荐

  1. 安装edX DevStack

    概述 edX Developer Stack 就是通常我们所说的Devstack,是为本地开发所设计的一个Vagrant实例. Devstack: 和产品(edx Product Stack)对系统的 ...

  2. [topcoder]BusinessTasks

    水题,不值一提.http://community.topcoder.com/stat?c=problem_statement&pm=1585&rd=6535 import java.u ...

  3. Java程序发展之路

  4. USB (Universal Serial Bus)

    USB歷史簡介 USB規格演變 標準 USB 2.0 介面 實體層 訊號傳輸 傳輸速率 網路層 USB 通訊模型 Endpoints 傳輸型態 USB 資料連結 Transaction Frame P ...

  5. C++类中静态变量和静态方法使用介绍!

    原链接:http://www.ecoviews.cn/net/archives/216.html 静态成员的提出是为了解决数据共享的问题.实现共享有许多方法,如:设置全局性的变量或对象是一种方法.但是 ...

  6. 【HDOJ】1042 N!

    肯定是大叔,本来以为用加法做乘法,后来想想这样麻烦,还是可以使用乘法的,按位乘,ov可以看成不止一位,程序如下所示: #include <stdio.h> #define MAX 4000 ...

  7. tlplayer for ios V1.1.1加密测试版本

    2014-06-22 修正稳定性. 大家还是可以从原来的下载地址下载. 此为tlplayer for ios版本,可以播放加密视频与非加密视频. 加密视频下载地址:http://blog.csdn.n ...

  8. MapReduce——计算温度最大值 (基于全新2.2.0API)

    MapReduce——计算温度最大值 (基于全新2.2.0API) deprecated: Job类的所有Constructors, 新的API用静态方法getInstance(conf)来去的Job ...

  9. rebuild过程

    /** The class defining a handle to an Innodb table */ class ha_innobase: public handler { row_prebui ...

  10. windows播放声音

    一般播放MP3常见的有两种方法,一种是自己解码,另外一种用系统的库,比如MCI,当然如果可以用控件直接用个控件会更方便. 1.      使用mci #include <windows.h> ...