total noob question but I cannot find any solutions to this sorry so last resort is to ask here.
I am trying to learn pug. Have created a boilerplate project and unable to render index page. Ive searched and read as much as I can but all I get is 'Error parsing body of the with expression' error. The index.js looks as simple as follows but stopping me in my tracks:
var express = require('express');
var router = express.Router();
// GET home page.
router.get('/', (req, res) => {
res.render('index', { title: 'Express' });
});
module.exports = router;
if anyone can provide a one liner to point me in the right direction to resolve this and keep rolling on my pug and nodejs journey I'd really appreciate it. Pug is appearing very difficult at this stage despite all the raving about it :/
I have checked one of my old projects. You can try something like this:
Install pug:
$ npm install pug --save
Then set up the app:
const express = require('express')
const app = express()
const port = 3000
// you don’t have to specify the engine or load the template engine module in your app;
// Express loads the module internally, as shown below (for the above example).
app.set('view engine', 'pug')
// views, the directory where the template files are located
// This defaults to the views directory in the application root directory.
app.set('views', './views')
app.get('/', (req, res) => {
res.render('index', { title: 'Hey', message: 'Hello there!' })
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Example pug file:
html
head
title= title
body
h1= message