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 ?
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 ?
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");
Address is already in use, you should change the port from for example 3000 to 3001 for the second instance of the script.
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.