ShipIt节点/用PM2快速部署 – 不能设置正确的NODE_ENV

我正在尝试使用ShipIt(w ships-npm插件)在正确的环境中启动我的节点应用程序? 我正在把它部署在env中,但是应用程序从开发模式开始显示yj -he process.env.NODE_ENV

部署与船舶

>$ shipit staging deploy Starting deployment... .... Running 'start_server' task... Running "cd /opt/hello/releases/20161128182300 && npm start" on host "myhost.live". @myhost.live @myhost.live > hello-world-express@0.0.1 start /opt/hello/releases/20161128182300 @myhost.live > pm2 startOrReload ecosystem.json @myhost.live @myhost.live [PM2] Applying action reloadProcessId on app [hello](ids: 0) @myhost.live [PM2] [hello](0) ✓ @myhost.live ┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬────────── @myhost.live │ App name │ id │ mode │ pid │ status │ restart │ uptime 

├──────────┼────┼──────┼──────┼────────┼─────────┼ ──────────────────────────────────────@ myhost.live│你好│0│叉│7224│在线│2│0
└──────────┴────┴──────┴──────┴────────┴─────────┴ ────────────────────────────myhost16.live使用pm2 pm2 show <id|name>来获得更多关于应用程序的详细信息9.01之后完成的“start_server”小号

我认为部署在“舞台”模式将NODE_ENV设置为“舞台”…不知道

hello.js

 var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World! Now you can call Express at 3637'); }); var port = process.env.PORT || 3637; app.listen(port); console.log('Now on ' + process.env.NODE_ENV + ' server'); console.log('Express app listening on localhost:'+ port); 

控制台日志状态:

 0|hello | Now on development server 0|hello | Express app listening on localhost:3637 

shipitfile.js

 ... // this task starts the application with PM2 shipit.blTask('start_server', function () { var cwd = shipit.releasePath; return shipit.remote( "cd " + cwd + " && npm start"); }); shipit.on('deployed', function () { console.log("Deployed !"); shipit.start('start_server'); }); ... 

的package.json

 ... "main": "hello.js", "scripts": { "start": "pm2 startOrReload ecosystem.json", ... 

ecosystem.json

 { "apps" : [ { "name": "hello", "cwd": "/opt/hello/current", "script": "hello.js", "args": "", "watch": true, "node_args": "", "merge_logs": true, "env": { "NODE_ENV": "development" }, "env_production": { "NODE_ENV": "production" }, "env_staging": { "NODE_ENV": "staging" } }] } 

我的ecos.js文件有什么问题?

感谢您的反馈

使用PM2,要使用生产环境variables(在env_production中设置),您需要指定–env选项。

在这里你可以find更多关于它的信息。

为了解决你的问题,只需在package.json中添加–env production到你的start属性:

 "start": "pm2 startOrReload ecosystem.json --env production",