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 trialDehn Hunsworth
7,189 Pointscant get server running
Been following the code pretty exact i believe but I am unable to even get the server going. error message that appears in terminal not much help.
Here is the message:
[nodemon] starting `node app.js`
C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\node_modules\path-to-regexp\index.js:63
path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/?'))
^
TypeError: Cannot read property 'length' of undefined
at pathtoRegexp (C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\node_modules\path-to-regexp\index.js:63:49)
at new Layer (C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\node_modules\express\lib\router\layer.js:45:17)
at Function.use (C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\node_modules\express\lib\router\index.js:464:17)
at Function.<anonymous> (C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\node_modules\express\lib\application.js:220:21)
at Array.forEach (<anonymous>)
at Function.use (C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\node_modules\express\lib\application.js:217:7)
at Object.<anonymous> (C:\Users\The Huns\Desktop\Web-Dev\Team Treehouse\flashcardsExpress\app.js:16:5)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
[nodemon] app crashed - waiting for file changes before starting...
and the cards.js where I had been making the most recent changes:
const express = require("express");
const router = express.Router();
const { data } = require("../data/flashcardData.json");
const { cards } = data;
router.get("/", (req, res) => {
const numberOfCards = cards.length;
const flashCardId = Math.floor(Math.random() * numberOfCards);
res.redirect(`/cards/${flashCardId}?side=question`);
});
router.get("/:id", (req, res) => {
const { side } = req.query;
const { id } = req.params;
const text = cards[id][side];
const { hint } = cards[id];
const templateData = { id, text };
if (side === "question") {
templateData.hint = hint;
templateData.sideToShow = "answer";
} else if (side === "answer") {
templateData.sideToShow = "question";
}
res.render("card", templateData);
});
module.exports = router;
Sure it is something simple but i have been looking at it for hours and my head hurts... Thanks.
Dehn Hunsworth
7,189 PointsDehn Hunsworth
7,189 PointsDeleted a variable from my app.js that was just a test and unused and still no server but the message has changed.
and the app.js :