1

I am trying to run two node.js application in my development machine but the second application throwing the following exception while running.

Is there any way to run these two applications in parallel way ?

enter image description here

enter image description here

Nitish Katare
  • 1,147
  • 2
  • 12
  • 22
  • 3
    Are both applications trying to run on port 3000? – Tom Aug 27 '14 at 12:53
  • Explaining the actual error: EADDRINUSE means '**error, address in use**'. See http://www.gnu.org/software/libc/manual/html_node/Error-Codes.html for the meanings of all these errors. – mikemaccana Aug 27 '14 at 12:59

3 Answers3

2

You need to use a different port since 3000 is already in use.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3001, "127.0.0.1");
ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
1

Address is already in use, you should change the port from for example 3000 to 3001 for the second instance of the script.

michelem
  • 14,430
  • 5
  • 50
  • 66
1

You can't bind two sockets on the same port. Hence the error.

The usual good practice is to rely on the PORT environment variable so as to be able to quickly change the listening port from the command line.

var http = require('http');
var port = process.env.PORT || 3000;

http.createServer().listen(port);

Then launch your application:

$ PORT=8080 node app.js

See here for cross-platform instructions on how to define environment variables from the command line.

Community
  • 1
  • 1
aymericbeaumet
  • 6,853
  • 2
  • 37
  • 50