我試圖在部署時開始在正確的環境我節點應用與ShipIt(W艘NPM插件)?我在臨時ENV部署它,但應用程序開發模式中啓動,說明顯示YJ-他process.env.NODE_ENVShipIt節點/快速部署,PM2 - 不能設置正確的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 > [email protected] 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 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"
}
}]
}
有什麼錯我的ecosystem.js文件?
感謝反饋
謝謝!在這種情況下,我需要設置2個腳本,開始分期,並開始生產在我的package.json文件... – erwin