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

jason limmm
jason limmm
7,854 Points

error with web server

it says 'Error: Cannot find module './routes/card'

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());

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

const mainroute=require('./routes');
const cardroutes=require('./routes/card')

app.use(mainroute);
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!')
});

cards.js

const express = require('express');
const router = express.Router();
const data = require('../../data/flashcardData.json').data;
const cards = data.cards;

router.get('/', (req, res) => {
    res.render('card', { question: cards[0].question, hint: cards[0].hint});
});

module.exports = router;

the cards.js file is store in a folder called card which stored in a folder called routes

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,838 Points

Looks like a potential route path issue... sounds like the path maybe './routes/card/cards', but I can't be sure, since I don't know the exact file structure.