O'Reilly logo

CoffeeScript Programming with jQuery, Rails, and Node.js by Michael Erasmus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a view

Similar to other web frameworks such as Rails, Express has the concepts of views, which let you separate your UI from your application using separate files. Usually, these are written using a templating language such as Jade. Let's create a view for our root action.

To do this, we'll need to:

  1. Create a views folder and add a Jade view file.
  2. Configure our Express application to be aware of a folder where the views will be stored, and which templating library we're using.
  3. Change our index route to render our view.

Let's create a new folder in our project root called views. Inside this folder, we create a new file named index.jade. This is how it should look:

doctype 5
html
  head
    title Our Jade view
  body
    p= message

As you can see, Jade offers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required