Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
using common layout for all the pages in pug

I am trying out pug with express

views/layout.pug 

doctype html
html
  head
    title= title
    link(rel="shortcut icon", href="favicon.ico", type="image/x-icon")
    link(rel='stylesheet', href='/assets/application.css')
    link(rel='stylesheet', href="assets/libs/bootstrap/dist/css/bootstrap.min.css")
  body    
    script(src="assets/libs/jquery/dist/jquery.min.js")
    script(src='assets/libs/bootstrap/dist/js/bootstrap.min.js')
    script(src="assets/application.js")
    block content

This is the router for User page.

routes/user.js

var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.render('user/index');
});

module.exports = router;

I have my view for user/index page. I extends the layout from the views. User index page using the layout. layout.pug is present in views folder.

If I add a layout.pug inside views/user it works. But how to use the views/layout.pug

/views/user/index.pug

extends layout


block content
    h1
     | User index

i get the following error. it is looking for layout in view/user folder. How to make it to use view/layout.pug.

Error: ENOENT: no such file or directory, open 'C:\my_projects\myexpressapp\views\user\layout.pug'
    at C:\my_projects\myexpressapp\views\user\index.pug line 1
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Function.read (C:\my_projects\myexpressapp\node_modules\pug-load\index.js:69:13)
    at Object.read (C:\my_projects\myexpressapp\node_modules\pug\lib\index.js:147:25)
    at C:\my_projects\myexpressapp\node_modules\pug-load\index.js:24:25
    at walkAST (C:\my_projects\myexpressapp\node_modules\pug-walk\index.js:23:18)
    at C:\my_projects\myexpressapp\node_modules\pug-walk\index.js:104:20
    at Array.reduce (native)
    at walkAndMergeNodes (C:\my_projects\myexpressapp\node_modules\pug-walk\index.js:103:18)
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

In your app.js file, check whether you have defined the views properly.

View engine should be set to pug and views folder should be set properly as described below in app.js

app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
about 4 years ago · Santiago Trujillo Report

0

You have to set the baseDirectory variable.

I'm not familiar with Express, I found the answer How do you set jade basedir option in an express app? (the "basedir" option is required to use "extends" with "absolute" paths)

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!