How to do it...

We'll require pino and express-pino-logger at the top of the index.js file:

const {join} = require('path') 
const express = require('express') 
const pino = require('pino')() 
const logger = require('express-pino-logger')({ 
  instance: pino 
}) 
const index = require('./routes/index') 

Notice how we instantiate a Pino instance by immediately calling the function returned from require('pino') and then pass that as the instance property of the object passed to the function returned from require('express-pino-logger').

This creates the logger middleware, let's register the middleware. Just underneath the second call to app.set we can add the following line:

app.use(logger) 

At the bottom of index.js we'll modify the app.listen callback like so:

app.listen(port, () => { 
  pino.info(`Server listening on port ${port}`) 
}) 

Let's also add a log message to the GET route in our routes/index.js file:

router.get('/', function (req, res) { 
  const title = 'Express' 
  req.log.info(`rendering index view with ${title}`) 
  res.render('index', {title: 'Express'}) 
}) 

Now let's start our server:

$ node index.js 

Then, if we make a request to the server by navigating to http://localhost:3000 in the browser, log messages similar to those shown in the following screemshot should be generated:

Pino
For more on Pino and express-pino-logger see http://npm.im/pino and http://npm.im/express-pino-logger.