

Return response.render( " index ", syntax. extends layout.pug block scripts script (src '/jquery.js') script (src '/pets.js') block content h1 title - var pets 'Cat', 'dog' each petName in pets include pet.pug. Instead of overriding that default, we will also create a folder called views.Ĭonst colors = Īpp.set( " view engine ", " pug ") // notice here we are telling express to render views using the pug templating engine. In a new PUG file, you first use extend to inherit a PUG, then define the code block of the same name to implement the replace.

By default, express expects a folder containing templates to be called views. There are quite a few we can use with Node.js including ejs, but we will be using one called pug (formerly known as jade).īefore we introduce the pug syntax, let's first start a new project and see what we need to include. In order to do that, we need to make use of a templating engine (a tool for dynamically rendering HTML using server data). If we want to simply send HTML back we can use ndFile, but since we are using server-side templates, we will be using a method called render. So far we have only seen how to respond by sending text, but when building server-side applications, we usually want to send back HTML or JSON / XML (if we're building an RESTful API). By the end of this chapter, you should be able to:
