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 Getting Started with Express Creating a Route with Express

1 Answer

Hi Felix, You didn't mention what code you are actually using, just you were not getting the same results so I'm going to answer based off of what I recall from this section. Hopefully by now you have this figured out but in case you don't I hope it helps.

If you have your own version of Express open on your editor, your code generally will look like this:

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

app.get('/', function (req, res) { // "/" = your root, req = request, res = response
    res.send('Hi der!') /*<-- will either be a root page to serve or another page */
})

app.listen(3000, function() {
    console.log('App is listening on port 3000!')
})

Make sure you restart the server so it will capture any changes you've made (and clear the "Cannot GET /" error) ctrl+c to stop itfollowed by node + index.js (or your insertion point filename) in your terminal then navigate to the page in your browser - for this example it would be "localhost:3000" or "localhost:3000/about" to serve the root "landing" or "about" page.

--> if you are using Nodemon just type "nodemon"in your terminal.

For further tips on Express routes and getting started here are some good links:

Express Getting Started

Basic Express Routing

Express Routes