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 Express Basics (2015) Using Templates with Express Using Jade in your Express App

Michel Moreau L
Michel Moreau L
21,751 Points

Hi guys! I got this problem when I tried to run app.js with the rendering of index.jade:

Error: Cannot find module 'jade'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at new View (C:\Users\Michel\desktop\webprojects\treehouseexpress\test\express-basics\node_modules\express\lib\view.js:78:30)
    at EventEmitter.render (C:\Users\Michel\desktop\webprojects\treehouseexpress\test\express-basics\node_modules\express\lib\application.js:569:12)
    at ServerResponse.render (C:\Users\Michel\desktop\webprojects\treehouseexpress\test\express-basics\node_modules\express\lib\response.js:961:7)
    at C:\Users\Michel\desktop\webprojects\treehouseexpress\test\express-basics\src\express-basics\src\app.js:12:6
    at Layer.handle [as handle_request] (C:\Users\Michel\desktop\webprojects\treehouseexpress\test\express-basics\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Michel\desktop\webprojects\treehouseexpress\test\express-basics\node_modules\express\lib\router\route.js:131:13)

Don't mind about the weird directory unless you think it might be the problem. Also you can see my code of app.js here :

'use strict';

var express = require('express'),
    posts = require('./mock/posts.json');

var app = express();

app.set('view engine', 'jade');
app.set('views', __dirname + '/templates');

app.get('/', function(req, res){
    res.render('index.jade');
});

app.get('/blog/:title?', function(req,res) {
    var title = req.params.title;
    if (title === undefined) {
        res.status(503);
        res.send("This page is under construction");
    } else {
        var post = posts[title];
        res.send(post);
    }
});

app.listen(3000, function(){
    console.log("The frontend server is running on port 3000!")
});

It tells me jade is not installed, although it is, and I can see it in my package.json and in node_modules

Thanks in advance for the tips!

3 Answers

Here's a solution for people who'd rather not clone the project each time we move on to a different exercise: Install jade in your project file.

The command:

$ npm install jade --save

Worked for me.

Darryn Smith
Darryn Smith
32,043 Points

I had this problem too.

Turned out all I needed to do was get to my shell and run

'npm install'

after running

'git checkout usingJade'.

On the one hand I appreciate the opportunity to learn and figure things out for myself, but I can't help but think I'd've appreciated it being mentioned in the teacher's notes since the procedure for checking out the current git branch is listed in every single video.

Just sayin'

npm install fixed my issue. Thanks

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,671 Points

It looks like you aren't requiring Jade in your app.js.

Try adding:

jade = require('jade'),
Michel Moreau L
Michel Moreau L
21,751 Points

Thank you Rich. I tried your solution but it was not the problem. I solved it by modifying the path to my directory "express-basics". I would not be able to explain in details why it worked, but I think node was trying to access express in the wrong directory, and therefore it wasn't finding jade in the same path. In other words, there was some overlapping express modules installed in my path (I think). see: https://forums.openshift.com/nodejs-and-jade-error-cannot-find-module-jade

Thanks again for the quick response.