这是我的应用app.js
:
var express= require("express");
var app= express();
app.get('/',function(req,res){
console.log(req);
res.send("Hello world");
});
app.get('*', function(req, res){
res.send("Nothing to see here.", 404);
});
var port= process.env.PORT || 3000;
app.listen(port,function(){
var host= server.address().address;
var port= server.address().port;
});
当我在本地运行nodejs app.js
时,这可以按预期工作。我可以转到localhost:3000
并查看Hello world
,但是当我将其推送到Heroku时,我会在日志中找到它:
2016-10-25T03:37:09.449732+00:00 heroku[web.1]: Starting process with command `node app.js`
2016-10-25T03:37:11.207319+00:00 app[web.1]: /app/app.js:47
2016-10-25T03:37:11.207341+00:00 app[web.1]: var host= server.address().address;
2016-10-25T03:37:11.207342+00:00 app[web.1]: ^
2016-10-25T03:37:11.207343+00:00 app[web.1]:
2016-10-25T03:37:11.207343+00:00 app[web.1]: ReferenceError: server is not defined
2016-10-25T03:37:11.207344+00:00 app[web.1]: at Server.<anonymous> (/app/app.js:47:28)
2016-10-25T03:37:11.207345+00:00 app[web.1]: at Server.g (events.js:291:16)
2016-10-25T03:37:11.207345+00:00 app[web.1]: at emitNone (events.js:86:13)
2016-10-25T03:37:11.207346+00:00 app[web.1]: at Server.emit (events.js:185:7)
2016-10-25T03:37:11.207346+00:00 app[web.1]: at emitListeningNT (net.js:1278:10)
2016-10-25T03:37:11.207347+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:71:11)
2016-10-25T03:37:11.207348+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:98:9)
2016-10-25T03:37:11.207349+00:00 app[web.1]: at Module.runMain (module.js:592:11)
2016-10-25T03:37:11.207349+00:00 app[web.1]: at run (bootstrap_node.js:394:7)
2016-10-25T03:37:11.207350+00:00 app[web.1]: at startup (bootstrap_node.js:149:9)
2016-10-25T03:37:11.287706+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-25T03:37:11.290415+00:00 heroku[web.1]: Process exited with status 1
这里发生了什么?
答案 0 :(得分:3)
您在此处显示的内容没有定义变量'server'。不知道为什么它在本地工作,但没有理由它应该工作。
发布你的完整app.js和你的package.json,这可能会帮助我们更具体。