本地主机和其他域之间的 NodeJS 部署混淆?
NodeJS Deployment confusion between localhost and other domain?
我有一个简单的程序,在本地主机上运行良好。
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var port = process.env.PORT || 8080;
var host = "127.0.0.1";
var server = app.listen(port, host, function(){
console.log("Server running in : ",host ," with port no : ",port);
});
尝试使用 codeship 将其部署到 heroku。除了部署测试命令的最后一行,即 node index.js
反过来指的是 127.0.0.1 并停止部署,一切都在构建完美。我可以知道我需要在这里为 host 和 port address
更改一些东西吗
在作为 Heroku Toolbelt 一部分的工头的帮助下,尝试 运行 在本地主机上运行您的应用程序。例如:
foreman start web
您应该会在 http://localhost:5000 或您在 package.json
文件中指定的端口上看到您的应用 运行ning。
建议此 link 以供进一步查询:
prerequisites 在 Heroku 上部署节点应用程序?
只是不要提供主机:
var server = app.listen(port, function() {
console.log('Server listening on', port);
});
(这意味着,"accept connections on any host, on this port",与你正在尝试的意味着,"accept connections on 127.0.0.1 on this port")
我能够按照这些步骤成功托管它
As suggested by @hunterloftis, i removed hostname.
More importantly, Procfile was missing,so added it and deployed successfully
我有一个简单的程序,在本地主机上运行良好。
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var port = process.env.PORT || 8080;
var host = "127.0.0.1";
var server = app.listen(port, host, function(){
console.log("Server running in : ",host ," with port no : ",port);
});
尝试使用 codeship 将其部署到 heroku。除了部署测试命令的最后一行,即 node index.js
反过来指的是 127.0.0.1 并停止部署,一切都在构建完美。我可以知道我需要在这里为 host 和 port address
在作为 Heroku Toolbelt 一部分的工头的帮助下,尝试 运行 在本地主机上运行您的应用程序。例如:
foreman start web
您应该会在 http://localhost:5000 或您在 package.json
文件中指定的端口上看到您的应用 运行ning。
建议此 link 以供进一步查询: prerequisites 在 Heroku 上部署节点应用程序?
只是不要提供主机:
var server = app.listen(port, function() {
console.log('Server listening on', port);
});
(这意味着,"accept connections on any host, on this port",与你正在尝试的意味着,"accept connections on 127.0.0.1 on this port")
我能够按照这些步骤成功托管它
As suggested by @hunterloftis, i removed hostname.
More importantly, Procfile was missing,so added it and deployed successfully