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

2
  • 3
    Are both applications trying to run on port 3000? Commented Aug 27, 2014 at 12:53
  • Explaining the actual error: EADDRINUSE means 'error, address in use'. See gnu.org/software/libc/manual/html_node/Error-Codes.html for the meanings of all these errors. Commented Aug 27, 2014 at 12:59

3 Answers 3

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");
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.