loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Issue deploying in loopback.io application - ERROR: EADDRINUSE 0.0.0.0:8080

Open cchacons opened this issue 10 years ago • 3 comments

Hi Everyone,

I am trying to deploy my loopback.io application into my server platform: modulus.io but it is failing with the following error: "EADDRINUSE 0.0.0.0:8080".

In my local machine (mac OS X) it runs properly but on the servers it fails. Locally, I'm able to run the app using "node ." and I'm able to go to the API explorer and also run queries.

I'm not sure why the app is listening to that IP and PORT (0.0.0.0:8080) because in my server/server.js and server/config.json I'm using other ports.

server/server.js: var port = process.env.PORT || 8329; app.listen(port); console.log('Application Listening on port %s',port);

server/config.json: "restApiRoot": "/api", "host": "0.0.0.0", "port": 3001,

Does any one know what could be causing this problem?

ERROR DETAILS

Now using node v4.2.4 Found package.json: ./package.json Start script specified in package.json: node . Running command: npm start

[email protected] start /mnt/app node .

Application Listening on port 8080 events.js:141 throw er; // Unhandled 'error' event ^

Error: listen EADDRINUSE 0.0.0.0:8080 at Object.exports._errnoException (util.js:870:11) at exports._exceptionWithHostPort (util.js:893:20) at Server._listen2 (net.js:1238:14) at Server._listen2 (/mnt/app/node_modules/async-listener/index.js:72:23) at listen (net.js:1274:10) at net.js:1383:9 at doNTCallback3 (node.js:452:9) at process._tickDomainCallback (node.js:399:17) at process. (/mnt/app/node_modules/async-listener/index.js:19:15) at Function.Module.runMain (module.js:469:11)

npm ERR! Linux 3.13.0-74-generic npm ERR! argv "/mnt/app/.modulus/nvm/versions/node/v4.2.4/bin/node" "/mnt/app/.modulus/nvm/versions/node/v4.2.4/bin/npm" "start" npm ERR! node v4.2.4 npm ERR! npm v3.5.2 npm ERR! code ELIFECYCLE npm ERR! [email protected] start: node . npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start script 'node .'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the algobreaker package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node . npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs algobreaker npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls algobreaker npm ERR! There is likely additional logging output above.

cchacons avatar Dec 30 '15 18:12 cchacons

I don't think config.json populates process.env.PORT. You'll have to set the PORT environment variable in your modulus app using modulus env set PORT 3001. More info: http://help.modulus.io/customer/portal/articles/1702084-environment-variable-commands

rawrmaan avatar Dec 30 '15 19:12 rawrmaan

hi rawrmaan, I'm trying to follow modulus guidelines. My understanding is that we are not supposed to set the PORT variable, instead that gets assigned by modules based on which ports are available on the servo that your app is running. http://help.modulus.io/customer/portal/articles/1660583-application-guidelines

All apps should be configured to listen on the port provided in the PORT environment variable (process.env.PORT). This variable will always hold the port available inside your servo that allows your application to be accessible within the Modulus infrastructure. your application. The Modulus routing system will handle directing requests from the internet to your application and vice-versa.

var http = require('http');

http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(process.env.PORT);

console.log('Server running on port ' + process.env.PORT);

cchacons avatar Dec 30 '15 22:12 cchacons

I have found the problem and fixed it.

It was on server/server.js. It was okay to initialize the port based on the environment variable process.env.PORT || 8329; but I shouldnt be calling app.listen(port) because that is called later by loopback. So that was causing the port to be already in used when loopback calls it. Also moved the port variable assignment at the beginning of the server.js before loopback is executed.

var port = process.env.PORT || 8080; console.log('Setting port to %s',port);

var app = module.exports = loopback();

app.start = function() { // start the web server return app.listen(function() { app.emit('started'); var baseUrl = app.get('url').replace(//$/, ''); console.log('Web server listening at: %s', baseUrl); if (app.get('loopback-component-explorer')) { var explorerPath = app.get('loopback-component-explorer').mountPath; console.log('Browse your REST API at %s%s', baseUrl, explorerPath); } }); };

cchacons avatar Dec 31 '15 00:12 cchacons