Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Linking Around the Application

Martin Coutts
Martin Coutts
18,154 Points

Invalid Status Code

Getting this set of data in my terminal even though from what I can see my code is correct RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (http_server.js:208:11) at ServerResponse._implicitHeader (_http_server.js:199:8) at write (http_outgoing.js:593:9) at ServerResponse.end (_http_outgoing.js:714:5) at ServerResponse.send (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:221:10) at done (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:1004:10) at Object.exports.renderFile (/Users/martincoutts5/flashcards/node_modules/pug/lib/index.js:421:12) at View.exports.express as engine at View.render (/Users/martincoutts5/flashcards/node_modules/express/lib/view.js:135:8) at tryRender (/Users/martincoutts5/flashcards/node_modules/express/lib/application.js:640:10) RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:208:11) at ServerResponse._implicitHeader (_http_server.js:199:8) at write (http_outgoing.js:593:9) at ServerResponse.end (_http_outgoing.js:714:5) at ServerResponse.send (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:221:10) at done (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:1004:10) at Object.exports.renderFile (/Users/martincoutts5/flashcards/node_modules/pug/lib/index.js:421:12) at View.exports.express as engine at View.render (/Users/martincoutts5/flashcards/node_modules/express/lib/view.js:135:8) at tryRender (/Users/martincoutts5/flashcards/node_modules/express/lib/application.js:640:10) RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:208:11) at ServerResponse._implicitHeader (_http_server.js:199:8) at write (http_outgoing.js:593:9) at ServerResponse.end (_http_outgoing.js:714:5) at ServerResponse.send (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:221:10) at done (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:1004:10) at Object.exports.renderFile (/Users/martincoutts5/flashcards/node_modules/pug/lib/index.js:421:12) at View.exports.express as engine at View.render (/Users/martincoutts5/flashcards/node_modules/express/lib/view.js:135:8) at tryRender (/Users/martincoutts5/flashcards/node_modules/express/lib/application.js:640:10) RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:208:11) at ServerResponse._implicitHeader (_http_server.js:199:8) at write (http_outgoing.js:593:9) at ServerResponse.end (_http_outgoing.js:714:5) at ServerResponse.send (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:221:10) at done (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:1004:10) at Object.exports.renderFile (/Users/martincoutts5/flashcards/node_modules/pug/lib/index.js:421:12) at View.exports.express as engine at View.render (/Users/martincoutts5/flashcards/node_modules/express/lib/view.js:135:8) at tryRender (/Users/martincoutts5/flashcards/node_modules/express/lib/application.js:640:10) RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:208:11) at ServerResponse._implicitHeader (_http_server.js:199:8) at write (http_outgoing.js:593:9) at ServerResponse.end (_http_outgoing.js:714:5) at ServerResponse.send (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:221:10) at done (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:1004:10) at Object.exports.renderFile (/Users/martincoutts5/flashcards/node_modules/pug/lib/index.js:421:12) at View.exports.express as engine at View.render (/Users/martincoutts5/flashcards/node_modules/express/lib/view.js:135:8) at tryRender (/Users/martincoutts5/flashcards/node_modules/express/lib/application.js:640:10) RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:208:11) at ServerResponse._implicitHeader (_http_server.js:199:8) at write (http_outgoing.js:593:9) at ServerResponse.end (_http_outgoing.js:714:5) at ServerResponse.send (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:221:10) at done (/Users/martincoutts5/flashcards/node_modules/express/lib/response.js:1004:10) at Object.exports.renderFile (/Users/martincoutts5/flashcards/node_modules/pug/lib/index.js:421:12) at View.exports._express as engine at View.render (/Users/martincoutts5/flashcards/node_modules/express/lib/view.js:135:8) at tryRender (/Users/martincoutts5/flashcards/node_modules/express/lib/application.js:640:10)

The code I have written for the random redirect is here

router.get('/', (req, res) => { const numberOfCards = cards.length; const flashcardId = Math.floor(Math.random() * numberofCards); res.redirect( /cards/${flashcardId}?side=question ) });

2 Answers

Adam Beer
Adam Beer
11,314 Points

You forgot to use it the backticks inside the res.redirect(``). Hope this help.

Martin Coutts
Martin Coutts
18,154 Points

Noticed that after posting also I had numberofCards instead of numberOfCards

Thanks Adam