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. codeforces Vasya and Digital Root

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ /** * 当时比赛时,想得复杂了,也想偏了, * 1).写出来之后,结果达到了预期 ...

  2. ANDROID_MARS学习笔记_S02_002_Date\TimePicker

    一.文档用法 1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  3. [译]GotW #89 Smart Pointers

    There's a lot to love about standard smart pointers in general, and unique_ptr in particular. Proble ...

  4. URAL1029. Ministry(DP+路径)

    链接 路径麻烦啊 很多细节 倒回去搜一遍 卡了一节数据库.. #include <iostream> #include<cstdio> #include<cstring& ...

  5. Ajax的同步和异步

    在实际编程过程中,涉及到很多同步和异步的问题,例如: $("#btnTJ").bind("click", function () { //第一条语句 $.pos ...

  6. TFS源代码管理

    一.服务器配置 1.创建一个Visual Studio Online账户 打开VS,选择团队资源管理器(视图菜单下),然后在团队资源管理器中选择注册Team Foundation Service,打开 ...

  7. nginx 去掉服务器版本和名称和nginx_status 状态说明

    可能有时候我们看某些站点想知道别人在使用什么版本的web服务器之类的信息时,却发现并未显示版本号,甚至连WEB服务器都有变化,可以通过以下方法来隐藏Nginx.PHP的版本号信息,来提升一定的安全性: ...

  8. 利用URLRewriter重写url地址

    首先,当然是下载URLRewriter了 download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDN ...

  9. 使用PowerDesigner建立数据库模型

    转自:http://www.cnblogs.com/tonyepaper/archive/2008/02/12/1067260.html 1.       打开PowerDesigner,点击File ...

  10. selenium1.0和selenium2.0页面等待处理详解

    一.selenium1.0页面等待 1.……AndWait 经常会看到, selenium action命令中很多有这种……AndWait后缀, 例如click和clickAndWait命令: cli ...