1

So this is what I have in my server.js file.

 var app = require('express')();
 bodyParser = require('body-parser');

 app.listen(3000);

 app.use(bodyParser.urlencoded({
     extended true
 }));
 app.use(bodyParser.json());

 app.get('/items', function(req, res) {

     data = {
         brains: "squishy",
         relationships: "squishy",
         tickles: "harsh",
         taste: "sweet"
     }

     console.log(data.brains);
 });

I want all of my data as an output so I console logged data.brains and then when i checked my node inside my terminal, it will not generate any output getting stuck at starting 'node server.js' .. I don't know why it's not working. What is the issue?

2
  • what did you do, exactly? From what I understand, what you should be doing is: 1) run node server.js 2) while the command is still running, go to http://localhost:3000/ in a browser 3) check the console again Commented Nov 11, 2015 at 21:22
  • You should be going to http://localhost:3000/items after fixing the error that Jordan pointed out. Commented Nov 11, 2015 at 21:27

2 Answers 2

4

You need to run an HTTP request to your server to trigger that logging. Try visiting http://localhost:3000/items and it should log "squishy" as expected.

Essentially this code in your example registers the callback within it to respond to such an HTTP request:

app.get('/items', function(req, res) {

     data = {
         brains: "squishy",
         relationships: "squishy",
         tickles: "harsh",
         taste: "sweet"
     }

     console.log(data.brains);
});
Sign up to request clarification or add additional context in comments.

Comments

0

For one thing, you have a syntax error on line 6. {extended true} isn't valid JavaScript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.