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 REST APIs with Express Getting to Know REST APIs A Simple API

I am following the video but get a 'Cannot GET /' on my localhost:3000

const express = require('express');
const app = express();

app.get('/greetings', (req, res)=>{     // get takes 2 argument, first - the route we want to handle, second - callback function how we want to respond
    res.json({greeting: "Hello World!"});    //json in object
});     //because we build a rest api, we want to send back json instead of res.render('some_html_template')

app.listen(3000, () => console.log('Quote API listening on port 3000!'));

4 Answers

Hi!

In the video we aren't' handling any GET request to "/". We only handle GET requests to "/greetings". You would have to go to localhost:3000/greetings to see anything.

Check out the course Express Basics for some great information on this!

Hi Hanwen!

Is your app running (did you run npm start or nodemon in the console)?

Check the terminal for errors which may point to the problem. Your code looks good so it may be a package issue. Did you run npm install to install the dependencies from package.json.

MD MONIRUZZAMAN
MD MONIRUZZAMAN
6,130 Points

In case, you try in your local machine. You need to install express npm install express