3
var express = require('express');
app = express(),
jade = require('jade'),
path = require('path'),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
users = [];

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

//static path
app.use(express.static(path.join(__dirname,'public')));

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

server.listen('3000');
console.log('server started..');

I followed a video tutorial, I did the same thing but I got an error of cannot find module of [object Object]. The guy who did the video didn't include require('jade'), it worked for him, but it doesn't work for me. I says jade is not defined if I did not require jade.

6 Answers 6

12

Not relevant to this case, but might assist someone.

I had this problem, and found that a mistake in

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

caused it.

it should have been:

app.set('view engine', 'ejs');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that at least partially solved the problem I came here for.
3

Change

var express = require('express'); 

into

var express = require('express'),

Right now express is the only variable that is defined.

4 Comments

nice catch, I fixed my typo but it doesn't solve the problem.
Did you try to install jade with both npm install jade and npm install jade -g to see what happens? It seems there are some issues with loading one of your modules. Do you perhaps get other / more elaborate errors then the one in your question?
I pasted in my whole code. I found the fix, the jade should have ' like 'jade'lol!
Nice! I've watched your code for quite a while, but couldn't find that one :).
0

Need not import ejs module. Just pass string 'ejs' to the view engine. It will pick the module with the engine name given.

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

remove the importing module

jade = require('jade');

Comments

0

Two things to keep in mind you need:
Change this:

app = express(),
app.set('view engine', jade);

to:

app = express();
app.set('view engine', 'jade');

Comments

0

Change:

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

Into:

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

And

app = express(),

Into:

app = express();

Comments

-1

maybe you need to change

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

to

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

1 Comment

How does this add anything to the answer given by @Lawati97, several months ago?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.