user5539793
user5539793

Reputation: 81

Stuck at starting 'node server.js' .. won't get any output. What's the issue?

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?

Upvotes: 1

Views: 5859

Answers (2)

Alain O'Dea
Alain O'Dea

Reputation: 21686

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);
});

Upvotes: 4

Jordan Running
Jordan Running

Reputation: 106017

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

Upvotes: 0

Related Questions