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 trialSander de Wijs
Courses Plus Student 22,267 Points[SOLVED] router not working correctly
I have followed along with the video and set up a router that uses the api/ namespace. However when I try to visit the /todos page, I get an error 'Cannot GET /todos'. This is my code:
'use strict';
var express = require('express');
var app = express();
app.use('/', express.static('public'));
var router = express.Router();
router.get('/todos', function(req, res){
res.json({todos:[]});
});
app.use('/api', router);
app.listen(3000, function() {
console.log("Server running on port 3000");
});
1 Answer
Sander de Wijs
Courses Plus Student 22,267 PointsI just discovered the answer. I thought by defining the route /api for the router I could just call localhost:3000/todos. But this isn't the case. I still need to call /api/todos as defined in the router.
Iain Simmons
Treehouse Moderator 32,305 PointsIain Simmons
Treehouse Moderator 32,305 PointsHi Sander de Wijs, glad you sorted it out. I've marked your question as solved.