在Amazon EC2上運行。代碼由express-generator自動創建。儘管將端口設置爲80,但Express仍在監聽端口3000?
要啓動的應用程序我不得不這樣做:
須藤PORT = 80個NPM啓動
然後,我添加線14:
app.set('port', process.env.PORT || 80);
和66
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
現在我可以說啓動應用程序:
須藤NPM啓動
但它說 - Express服務器偵聽端口3000。我可以從我的瀏覽器訪問它,但爲什麼3000
的package.json
{
"name": "haha",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"express-generator": "^4.13.1",
"jade": "~1.11.0",
"kerberos": "file:kerberos",
"mongodb": "^2.0.52",
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0"
}
}
fyi,確保你轉換爲浮點數。 Env變量是字符串。即。 'app.set('port',Number(process.env.PORT)|| 80);' – agconti
謝謝,我做過了,但仍然在說3000. –
檢查你的package.json,也許有一個默認覆蓋你的配置 – Ludo