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
8,009 Points

page is not loading

here is my code, when i tried to load the page of the root route my page isn't loading and there isn't anything the chrome devtools console and the command prompt is telling me.

app.js

const express= require('express');
const app = express();
const port = 3000;
const bodyparser= require('body-parser');
const cookieparser= require('cookie-parser');

app.use(bodyparser.urlencoded({ extended: false }));
app.use(cookieparser());

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

app.listen(port, ()=>{
    console.log(`app is listening on port ${port}`);
});

const mainroute = require('./routes/index.js');
const products = require('./routes/products.js');

app.use('/', mainroute);

app.use('/products', products);

app.use((req, res, next)=>{
    const error = new Error('uh no!!!! no money for us!!!');
    next(err);
});

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

layout.pug

doctype html


html(lang="en")
    head 
        title=title
    body
        block content

mainpage.pug

extends layout

block content
    h1 Welcome to apple.con

index.js

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

router.get('/', (req, res)=>{
    res.render('mainpage', title='main page');
});

module.exports = router;