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

Katie Shook
Katie Shook
12,234 Points

not getting any information from the console. It's just printing {} in the terminal.

Hey everyone. I'm not getting any of that bulk info in the body that Andrew did. When I submit the form {} was printing in my terminal but now nothing is. Also not sure if this is related but my form keeps disappearing and I have to click on it. Here are some snippets of my code.

hello.pug : extends layout

block content h2 Welcome, Student! form(action='/hello' , method='post') label Please enter your name input(type= 'text' , name='name') button(type='submit') Submit

app.js : const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded( { extended : false } )); app.set('view engine', 'pug'); app.get('/hello', (req, res) => { console.dir(req.body); res.render('hello'); }) app.post('/hello', (req, res) => { res.render('hello'); })

Any help is appreciated! Thanks!

luther wardle
seal-mask
.a{fill-rule:evenodd;}techdegree
luther wardle
Full Stack JavaScript Techdegree Student 18,029 Points

Hi Katie, I have formatted your app.js for better readability. I am currently dealing with the same issue. If I run across a solution I will post it :)

In the meantime, if you are sure you have no syntax errors in your code, restarting your development server may resolve the issue, some changes simply might not have taken effect in your current instance of the server.

//app.js 

const bodyParser = require('body-parser'); 
app.use(bodyParser.urlencoded( { extended : false } )); 
app.set('view engine', 'pug'); 

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

 app.post('/hello', (req, res) => {
     console.dir(req.body)
     res.render('hello')
});

I have listed the commands for code formatting below for future reference.

Code Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

2 Answers