Anubhav Sahu Anubhav Sahu -5 years ago 252
Node.js Question

i was deploying my nodejs app on evennode but i am getting this error

i have been trying everything but it keeps throwing this error in the log. and says 502 bad gateway when trying to access the url.

throw er; // Unhandled 'error' event
Error: listen EACCES
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1221:19)
at listen (net.js:1270:10)
at net.js:1379:9
at nextTickCallbackWith3Args (node.js:453:9)
at process._tickCallback (node.js:359:17)
at Function.Module.runMain (module.js:443:11)
at startup (node.js:139:18)
at node.js:968:3

here's my app.js (also my start script as specified in package.json).

var app = require('express')();
var http = require('http').Server(app);
var path = require('path');
var io = require('')(http);

var routes = require('./routes/home');
var users = require('./routes/users');

io.on('connection', function(socket) {
console.log('a user connected');
socket.on('message', function (data) {
io.emit('msg', data);

http.listen(process.env.port, '', function(err) {
console.log('server runninng at ' + http.url );

although at console(stdout) it says
-> starting app
-> running server at undefined

Answer Source

You should update the process.env.port to process.env.PORT since env vars are case sensitive.

The listen should look like this:

http.listen(process.env.PORT, '', function(err) {
    console.log('server runninng at ' + http.url );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download