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 (2015) The Request and Response Objects in Express Requests and the request object

Bohdan Afanasyev
Bohdan Afanasyev
2,104 Points

No response in console on req or res

I am trying to strictly follow Huston and have the following issue, when I start node-inspector, create a breakpoint and type req or res in console I don't get any information there as Huston does (IncomingMessage). Can you please suggest what is done wrong?

My code from app.js:

 'use strict';

var express = require('express'),
      posts = require('./mock/posts.json');

var app = express();

app.get('/', function(req, res){
    res.send("<h1>I am loving Treehouse!</h1>");
});

app.get('/blog', function(req, res){ 
    res.send(posts);
});

app.listen(3000, function(){
    console.log("The frontend server is running on port 3000!")
});

And I have no error messages on running both node demon and inspector in 2 separated tabs in terminal.

8 Answers

Steve Brewer
Steve Brewer
15,030 Points

While not stopped at the breakpoint, the console won't always behave as expected.

In terminal run 'node-inspector'

Open node inspector at http://127.0.0.1:8080/?port=5858

In terminal run 'nodemon -debug src/app.js'

Switch back to node inspector window

Set break point to line 13

Open http://localhost:3000/blog

Switch back to node inspector and if you have a list in the 'breakpoints' window on the right, the console should work.

matiascao
matiascao
8,700 Points

Same problem here. I had to restart both nodemon and inspector to get it working.

Don Hamilton III
Don Hamilton III
31,828 Points

I'm also getting a similar problem. I haven't altered the code yet, just cloned it from the git repo. I get and error though that says, 'Uncaught ReferenceError: req is not defined(…)'.

Anybody have any idea on that?

Don Hamilton III
Don Hamilton III
31,828 Points

Update:

I updated Node Inspector via npm, and success! Not 100% sure why that worked since it seems to be the same version. But anybody having this issue, give this a try.

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

I'm sure you're miles beyond this by now, but for anyone else running into this issue: I think you might have typed 'req' into the localhost window rather than the node inspector window. I had a similar error as described above, but putting 'req' into the node inspector window just got no answer, while 'req' into the localhost window threw an error. (Also I left out the /blog part, lots of ways to screw up...)

Josh Kumm
Josh Kumm
6,099 Points

I had a similar issue and the resolution was two-fold:

  1. I was opening the Chrome console (CMD + ALT + C) as opposed to the Node-Inspector console. Typing "req" into the Chrome console returns the "VM600:1 Uncaught ReferenceError: req is not defined at <anonymous>:1:1" error. You need to open the Node-Inspector console using the arrow icon with the 3 lines in the bottom left corner.

  2. Even after working out point 1, my problem still wasn't solved due to the fact that the Node-Inspector console doesn't work with the latest version of Chrome. Entering "req" and pressing enter only moved the cursor to a new line. In order to get around this, I opened Node-Inspector and localhost: 3000 in Safari and this fixed the problem.

Hope this helps.

Christopher Clemons
PLUS
Christopher Clemons
Courses Plus Student 19,412 Points

I think the code is fine. Was having a similar problem but noticed the app hadn't run yet so app.get was never called. If you refresh the browser window containing the app (the one with localhost:3000 as the address) it should kick off the process. Then the breakpoint will be hit and you can inspect req and res. Hope this helps:)

Laurie Gray
Laurie Gray
23,119 Points

I had issues with the terminal not responding - simple fix >

Set your breakpoint in the Node Inspector window - then go to the localhost:3000 window and hit refresh - now simply return to the Node Inspector and you will find yourself paused at that breakpoint.

The console needs to be stopped in the body of the function to inspect/manipulate the objects in there.

Good luck.

Not working for me!

Laurie Gray
Laurie Gray
23,119 Points

Can you describe what is happening on both of your screens? The app has to be paused at a breakpoint for any kind of proper inspection - if you are typing commands in the console and nothing is happening then the app isn't paused at a breakpoint.

thanks for your reply, what happened is that my breakpoint was on the wrong line. Fixed it!

You should use the console of node inspector that at right top, not the browser console:)