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

Larisa Popescu
Larisa Popescu
20,242 Points

My /cards route is not working!

This is from the Express Basics course, "Parameters, Query Strings, and Modularizing Routes" part, the first video "Modular Routes".

All the other pages are working properly so I won't include index.js

This is my code from app.js

const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');

const app = express();

app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());

const colors = [
    'red',
    'orange',
    'yellow',
    'green',
    'blue',
    'purple'
  ];

app.set('view engine', 'pug'); 

const mainRoutes = require('./routes'); //it goes automaticly to index.js
const cardRoutes = require('./routes/cards');

app.use(mainRoutes);
app.use('/cards', cardRoutes);

app.use((req, res, next) => {
    const err = new Error('Not Found');
    err.status = 404;
    next(err);
});

app.use((err, req, res, next) => {
    res.locals.error = err;
    res.status(err.status);
    res.render('error');
});

app.listen(3000, () => {
    console.log('The application is running on localhost:3000!');
});

This is the code from cards.js

const express = require('express');
const router = express.Router();

router.get('/', (req, res) => {
    res.render('card', {
        prompt: "Who is buried in Grant's tomb?"
    });
}); 

module.exports = router;

When I try to go on the /cars route, I get this error:

RangeError: Invalid status code: 0

at ServerResponse.writeHead (_http_server.js:192:11)

at ServerResponse._implicitHeader (_http_server.js:157:8)

at ServerResponse.OutgoingMessage.end (_http_outgoing.js:573:10)

at ServerResponse.send (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\express\lib\response.js:221:10)

at done (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\express\lib\response.js:1004:10)

at Object.exports.renderFile (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\pug\lib\index.js:422:12)

at View.exports.__express [as engine] (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\pug\lib\index.js:465:11)

at View.render (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\express\lib\view.js:135:8)

at tryRender (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\express\lib\application.js:640:10)

at EventEmitter.render (E:\PracticeGrounds\PracticeGrounds\Treehouse\Express Basics\flashcards\node_modules\express\lib\application.js:592:3)

1 Answer

Larisa Popescu
Larisa Popescu
20,242 Points

I found the problem. It was in my card.pug file. I didn't delete the ul and li with the colors.