node.js - heroku app crash when listening on process.env.PORT -
when deploy on heroku :
app.js
var port = process.env.port || 8080; app.listen(port, function(){ console.log("listening on port : " + port); });
i error logs :
2014-11-08t18:05:34.300115+00:00 app[web.1]: events.js:72 2014-11-08t18:05:34.300402+00:00 app[web.1]: throw er; // unhandled 'error' event 2014-11-08t18:05:34.300404+00:00 app[web.1]: ^ 2014-11-08t18:05:34.303599+00:00 app[web.1]: error: hear eaddrinuse 2014-11-08t18:05:34.303605+00:00 app[web.1]: @ errnoexception (net.js:904:11) 2014-11-08t18:05:34.303607+00:00 app[web.1]: @ server._listen2 (net.js:1042:14) 2014-11-08t18:05:34.303608+00:00 app[web.1]: @ hear (net.js:1064:10) 2014-11-08t18:05:34.303610+00:00 app[web.1]: @ server.listen (net.js:1138:5) 2014-11-08t18:05:34.303628+00:00 app[web.1]: @ function.app.listen (/app/node_modules/express/lib/application.js:556:24) 2014-11-08t18:05:34.303629+00:00 app[web.1]: @ object.<anonymous> (/app/bin/www:7:18) 2014-11-08t18:05:34.303630+00:00 app[web.1]: @ module._compile (module.js:456:26) 2014-11-08t18:05:34.303632+00:00 app[web.1]: @ object.module._extensions..js (module.js:474:10) 2014-11-08t18:05:34.303633+00:00 app[web.1]: @ module.load (module.js:356:32) 2014-11-08t18:05:34.303635+00:00 app[web.1]: @ function.module._load (module.js:312:12)
but when hear straight on port 8080 work, , cant understand why :
var port = 8080; app.listen(port, function(){ console.log("listening on port : " + port); //it work });
i have started using nodejs , don't understand why crashes.
could either explain cause of or how "debug" this?
thanks !
the error "eaddrinuse" means listening port.
i guess nil listening 8080 on machine, why works when set directly.
use console.log(process.env.port)
print port you're trying hear to. check programme listening port using netstat -tunap
, should receive similar this:
proto recv-q send-q local address foreign address state pid/program name tcp 0 0 0.0.0.0:37 0.0.0.0:* hear 3425/inetd tcp 0 0 0.0.0.0:6000 0.0.0.0:* hear 3640/x tcp 0 0 0.0.0.0:113 0.0.0.0:* hear 3425/inetd tcp 0 0 0.0.0.0:22 0.0.0.0:* hear 7586/sshd
kill relevant programme , seek again.
to debug nodejs recommend node-inspector, easy utilize , uses chrome developer tools ui.
node.js heroku express
No comments:
Post a Comment