read

This is a tutorial for the bare minimum to use Jade templating in Express.

If you have already created a basic Express app, this is all you need to use Jade.

1. Create the views directory

Create a views directory in your project root directory.

2. Configure the view engine

You can actually use other directory names instead of views, as you will configure in your app.js as such:

app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
});

3. Write some jade code

Create index.jade in the views directory.

A basic example:

div.content
	p Hello Worls

4. Write the route

In the usual app.get(..) code, you can now render using the jade template.

app.get('/', function(request, response) {
    response.render('index.jade');
});

That’s it!


Image

@samwize

¯\_(ツ)_/¯

Back to Home