我成功地将我的node.js应用程序部署到heroku,但是当我访问该网站时出现错误
“错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定(bind)到 $PORT”
我的代码是
var router = require("./router.js");
// Create a web server
var http = require("http");
http.createServer(function (request, response) {
router.home(request, response);
router.user(request, response);
}).listen(1337);
console.log("Sever running at http://127.0.0.1:1337/");
我认为这与端口有关。有一个帖子和我的问题类似Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch) 但他们的解决方案是基于 Express 的。我的应用程序没有使用express。 有没有其他方法可以不将端口设置为固定号码?
最佳答案
是否使用express
并不重要。 Herouku 在 process.env.PORT
环境变量中为您绑定(bind)了一个端口。您需要像这样使用它:
var port = process.env.PORT || 1337
然后使用.listen(port)
确保您连接到浏览器中的正确端口(将端口记录到控制台以确保)
关于javascript - 如何在不使用 Express 的情况下将 Node 应用程序部署到 heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48977268/