Full-Stack Web Development with Vue.js and Node

(singke) #1
Building an Express Application Chapter 2

res.render('index', { title: 'Express' });
});

module.exports = router;

This means that when we access the home page, it renders a page called index that resides


inside views/index.pug and passes a parameter for the title to be displayed on the


page. Now, look at the index.pug file in the views folder, which has the following code:


extends layout

block content
h1= title
p Welcome to #{title}

This means it uses the layout from the layout.pug file and displays an h1 title as well as a


paragraph that renders the title that we passed from the route file. Hence, the output is as


follows:


Pretty simple and straightforward, right?


Request object


A request object is an object that contains the information about the HTTP request. The


properties of the request are:


query: This contains information about the parsed query strings. Accessed
via req.query.
params: This contains information about the parsed routing parameter. Accessed
via req.params.
body: This contains information about the parsed request body. Accessed
via req.body.
Free download pdf