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 trialMartin Coutts
18,154 PointsInvalid 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
11,314 PointsYou forgot to use it the backticks inside the res.redirect(``). Hope this help.
Martin Coutts
18,154 PointsNoticed that after posting also I had numberofCards instead of numberOfCards
Thanks Adam