Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Home Route

Error: listen EADDRINUSE :::3000

Hi.. I'm getting a rather cryptic error message: events.js:141 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE :::3000

my code:

var http = require('http'); http.createServer(function (request, response) { homeRoute(request, response); }).listen(3000); console.log('Server running at http://<workspace-url>/');

//2. handle http route GET / and POST / i.e. Home function homeRoute(request, response) { //if the url == "/" && GET if(request.url === "/") { //show the search field response.writeHead(200, {'Content-Type': 'text/plain'}); response.write("Header\n"); response.write("Search\n"); response.end('Footer\n'); } //if the url == "/" && POST //redirect to /:username }

any help would be appreciated!

thanks Ian

2 Answers

Matt F.
Matt F.
9,518 Points

Hello Ian,

I have encountered this many times when the app process was not ended properly.

The three options that I have used:(in order of my preference):

(1) Learn how to find and terminate the process. On my OS, I would run

sudo netstat -ap | grep :3000

to get the process id, and then I would would run

kill <process_id>

(2) Just switch the port number in your app to 3001, and it should run fine. (In your app, this is argument passed to listen).

(3) Reboot your computer and the error should be gone.

thanks! I switched to port 4567 and its now working.. just a question about your first solution.. is that for working w/in OSX? just curious if you know how I could do a similar find and terminate process in windows?

thank you!

Matt F.
Matt F.
9,518 Points

Hey Ian,

I think it also works on Mac, but I use it on a Linux machine.

This article might help you - though I have not used the method mentioned.

http://therealdanvega.com/blog/2015/04/16/windows-kill-process-by-port-number