Nodejs Heroku错误R10(启动超时) - > Web进程在启动后60秒内无法绑定到$ PORT

时间:2017-02-05 05:22:44

标签: node.js heroku

  • 我已经尝试过多次“错误R10”解决方案,但它并没有解决一个简单的Hello World问题,比如带有server.js,package.json,index.html和node_module

  • 特此添加server.js,package.json和错误日志

  • 目前在免费的heroku帐户上试用此应用程序

  • 是否有必要在github上上传nodejs app以在heroku上托管它

server.js

var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');

var port = 3000;

var app = express();

// Set Static Folder
app.use(express.static(__dirname));
// Body Parser MW
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));


var env = process.env.NODE_ENV || 'development';
if ('development' == env) {   
    app.use(express.static(__dirname + '/'));   
} else {
    app.use(express.static(__dirname + '/'));
}

app.get("/", function(req, res){
    res.render("index.html");
});

app.listen(port, function(){
    console.log("Server started ..!");
});

的package.json

{
      "name": "es1",
      "version": "1.0.0",
      "description": "eS",
      "main": "server.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC",
      "dependencies": {
        "body-parser": "^1.16.0",
        "express": "^4.14.0"
      }
    }

附加heroku日志:

https://drive.google.com/open?id=0B4XtAe7mRM6UVllTQWh1dmplZk0

1 个答案:

答案 0 :(得分:0)

按如下方式更改端口的值:

var port = process.env.PORT || 3000;