zoukankan      html  css  js  c++  java
  • [Whole Web, Nods.js, PM2] Passing environment variables to node.js using pm2

     learn how to pass environment variables to your node.js app using the pm2 config file. This is useful for setting options inside your app such as production or development.

    pm2.config.json:

    {
      "apps": [{
        "name": "App1",
        "script": "app1/server.js",
        "log_file": "log/app1.log",
        "error_file": "log/app1-err.log",
        "watch": true,
        "ignore_watch": ["file"],
        "env": {
          "STATUS": "GOOD"
        }
      },{
        "name": "App2",
        "script": "app2/server.js",
        "log_file": "log/app2.log",
        "error_file": "log/app2-err.log"
      }]
    }

    app1/server.js:

    Use process.env.STATUS to get the value:

    var http = require("http");
    var server = http.createServer(function(request, response){
        response.writeHead('200', {"Content-Type": "text/plain"});
        response.end("Hello from app, is this reload? " + process.env.STATUS);
    });
    server.listen(3002);
    console.log("Listen on port 3002");
  • 相关阅读:
    SpringMVC
    spring-02
    spring-01
    适配器模式
    状态模式
    抽象工厂模式
    观察者模式(发布-订阅模式)
    建造者模式(生成器模式)
    外观模式
    迪米特法则
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4478118.html
Copyright © 2011-2022 走看看