Running main http server with node.js on Mac

I am new to node.js and was trying to run the following tutorial example to set up a basic http server on my mac (OS X Yosemite 10.10.3):

var http = require("http");



http.createServer(function (request, response) {

request.on("end", function () {

    response.writeHead(200, {
        'Content-Type': 'text/plain'
    });

    response.end('Hello HTTP!');
});

}).listen(8080);

      

I get the following error while executing the code:

$ node http.js events.js: 85 throw er; // Unhandled 'error' event ^ Error: Listen for EADDRINUSE at export._errnoException (util.js: 746: 11) on Server._listen2 (net.js: 1156: 14) when listening (net.js: 1182: 10) on Server.listen (net.js: 1267: 5) on an object. (/ Users / sumankalyan / WebstormProjects / Node-Server / http.js: 25: 4) to Module._compile (module.js: 460: 26) to Object.Module._extensions..js (module.js: 478: 10 ) to Module.load (module.js: 355: 32) to Function.Module._load (module.js: 310: 12) to Function.Module.runMain (module.js: 501: 10)

Not sure if this is a localhost config issue or something. Any help is greatly appreciated.

+3


source to share


1 answer


Another application uses port 8080. You can run

lsof -i :8080

      



to find out what it is. You can also try a different port.

+4


source







All Articles