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 Deeper into Routing with Express The Request Object

Daniel Hernandez
Daniel Hernandez
13,437 Points

Whenever I install body-parser, pug is deleted. And whenever I install pug body-parser is deleted.

I have been having this problem with my project, I cannot install body-parser or pug without the other being deleted and my code becoming unable to run. I don't know if the javascript code will help but here it is

const express = require('express');

const app = express();

const bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({extended: false }));

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

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


app.get('/cards', (req, res) =>{
    res.render('card', { prompt: "Who is buried under Grant's Tomb"});
});

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


app.post('/hello', (req, res) =>{
        res.render('hello', {name: req.body.username});
});


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

Any help would be greatly appreciated

Have you tried installing both as dev dependencies? Use the --save-dev flag instead of just --save. You may need to remove them both first before trying to reinstall.

Here's my package.json file, with everything working fine.

  "name": "flashcards",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.2"
  },
  "devDependencies": {
    "body-parser": "^1.18.3",
    "pug": "^2.0.3"
  }
}

1 Answer

Daniel Hernandez
Daniel Hernandez
13,437 Points

Thanks, that did it! I feel silly for not thinking of that sooner