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 Express Basics (2015) Using Templates with Express Scaffolding Your Project’s Templates

Hi, it's throwing an error: listen EADDRINUSE :::3000 Unhandled "error" event.

I think it may have to do with other processes using the same port, I tried killall but it didn't resolve.

Here's the error msg and my code.

Imgur

'use strict';

var express = require('express'),
      posts = require('./mock/posts.json');

var app = express();

app.set('view engine', 'jade');
app.set('views', __dirname + '/templates')

app.get('/', function(req, res){
    res.render('index')
});

app.get('/blog/:title?', function(req, res){ 
    var title = req.params.title;
    if (title === undefined) {
        res.status(503);
        res.send("This page is under construction!");
    } else {
        var post = posts[title] || {};
        res.render('post', { post: post});
    }
});

app.listen(3000, function() {
    console.log("The frontend server is running on port 3000!");
});

4 Answers

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

If you use lsof, you can see what process is bound to the port with lsof -i:3000, and then force kill it by grabbing the process id (aka pid) and kill it with a kill -9 $pid.

lsof unfolded a hyperwebster, lsof -i:3000 is not showing anything at all, while i have the server running on that port, and It should be showing that process bound to that port.

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

you'll only see it if you have permissions; if you're running lsof as a different user than the app, try prefixing lsof -i:$port with sudo to make sure you have adequate permissions.

Got it to work after complete system restart.

got it, thanks.