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

I have to stop and start the server when I make a change in a pug view, why is that and is there a better?

const express = require('express');

const app = express();

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

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

app.get('/cards', (req, res) => {
    res.render('card', { prompt: "Who is buried in Grant's tomb", hint: "Think about whose tomb it is."});
});

app.listen(3000, () => {
    console.log('The application is running on localhost:3000');
});

1 Answer

Blake Larson
Blake Larson
13,014 Points

You can globally install nodemon.

npm install -g nodemon

Then you pass the file to nodemon the same way you do it with node

nodemon server.js

You can also write a nodemon start script in your package.json file.

"scripts": {
    "nodemon:start": "nodemon server"
  }

and use npm run nodemon:start