[英]Heroku node app not starting
我創建了一個非常基本的nodejs應用程序,該應用程序可以在本地工作。 當我將其推送到heroku服務器時,應用程序崩潰,日志中出現以下錯誤
var express = require("express");
var bodyParser = require("body-parser");
var app = express();
var port = process.env.PORT||3000;
app.use(bodyParser.urlencoded({extended:true}));
app.get('/',function(req,res){res.status(200).send('Hello World')});
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(400).send(err.message);
});
app.listen(port, function () {
console.log('Slack bot listening on port ' + port);
});
2016-01-05T19:39:14.346745+00:00 heroku[web.1]: Starting process with command `npm start` 2016-01-05T19:39:16.207970+00:00 app[web.1]: npm ERR! Linux 3.13.0-71-generic 2016-01-05T19:39:16.209056+00:00 app[web.1]: npm ERR! npm v3.3.12 2016-01-05T19:39:16.210546+00:00 app[web.1]: npm ERR! 2016-01-05T19:39:16.210779+00:00 app[web.1]: npm
package.json
{
"name": "slackbot",
"version": "1.0.0",
"description": "Slack Hello World Bot",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fffff/SlackBot.git"
},
"author": "Jasim Aboobacker",
"license": "ISC",
"bugs": {
"url": "https://github.com/fffff/SlackBot/issues"
},
"homepage": "https://github.com/fffff/SlackBot#readme",
"dependencies": {
"body-parser": "^1.14.2",
"express": "^4.13.3"
}
}
只需一步一步地執行這些步驟,它就可以很好地工作。 從網站下載並安裝node和npm。
其余命令如下
sudo -i
如果詢問,請輸入root密碼。
現在通過cmd / terminal轉到您選擇的項目文件夾
npm install -g express
npm install -g express-generator
express
cd . && npm install
SET DEBUG=<*folder name*>:* & npm start
現在,在文件夾中鍵入以下命令來設置git本地目錄。
git init
git add .
git commit -m "initial commits"
然后在Heroku中創建一個帳戶,並按照以下步驟操作。
heroku create <application_name>
git push heroku master
nb:在此過程中,可能會要求您輸入您的heroku帳戶的用戶名和密碼;因此請繼續進行操作。
現在鍵入以下內容以添加單個Web dyno
heroku ps:scale web=1
然后
heroku open
干杯!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.