Heroku节点应用程序无法启动

时间:2016-01-05 19:45:00

标签: node.js heroku

我创建了一个非常基本的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
     

ERR! https://github.com/npm/npm/issues

的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"
  }
}

1 个答案:

答案 0 :(得分:1)

请逐一按照这些步骤操作,它应该可以正常使用。 从网站下载并安装node和npm。

link node

link 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

干杯!!