Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Using Templates with Express Using Pug in Your Express App

Marlene Guzman
Marlene Guzman
9,231 Points

I am having issues running PUG

Please look at my code and tell me what I am not seeing... I installed PUG ..

i am getting the following error:

Error: Cannot find module 'pug' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15) at Function.Module._load (internal/modules/cjs/loader.js:506:25) at Module.require (internal/modules/cjs/loader.js:636:17) at require (internal/modules/cjs/helpers.js:20:18) at new View (/Users/marlene/node_modules/express/lib/view.js:81:14) at Function.render (/Users/marlene/node_modules/express/lib/application.js:570:12) at ServerResponse.render (/Users/marlene/node_modules/express/lib/response.js:1008:7) at app.get (/Users/marlene/expressPractice/app.js:8:6) at Layer.handle [as handle_request] (/Users/marlene/node_modules/express/lib/router/layer.js:95:5) at next (/Users/marlene/node_modules/express/lib/router/route.js:137:13)

Here is my code app.js

var express = require('express')

var app = express();

app.set('view engine', 'pug');

app.get('/', (req, res)=>{
 res.render('index'); 
});

app.get('/hello', (req, res)=>{
  res.send('<h1>Hello,  javascript developer!</h1>')
})

app.listen(3000, ()=> {
  console.log("the application is up and running on local host 3000")
}); 

index.pug

doctype html 
html(lang='en')
  head
    title
  body
    h1  the future of something magical 
    p  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus at neque nibh. Ut feugiat erat in orci varius, eu porta odio maximus. Nulla posuere nunc finibus hendrerit porttitor. Quisque eu porta odio, et eleifend dui. Aliquam feugiat nunc eget velit scelerisque, quis consectetur nisl placerat. Vivamus aliquam sem eget viverra consectetur. Etiam rutrum enim sed nulla malesuada auctor. 

1 Answer

Do you have Express installed locally? At your project directory in the terminal, try:

npm install express

If Express is not installed locally, your program may be running Express from another location. In turn, the program might be futilely looking for Pug in that other location.

(See answer by β€œyaya pro” at https://stackoverflow.com/questions/45342307/error-cannot-find-module-pug )