Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running basic http server using node.js on Mac

Tags:

node.js

macos

I'm new to node.js and was trying to run the following training example for setting 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 when executing the code:

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

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

like image 252
SumanK Avatar asked Feb 26 '26 00:02

SumanK


1 Answers

Another application is using the port 8080. You can run

lsof -i :8080

to see what it is. You can also just try another port.

like image 182
Hyo Byun Avatar answered Feb 28 '26 12:02

Hyo Byun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!