express.js not showing console.log message when routing

Viewed 35648

Note: I am very new to express

var express = require('express');
var app = express();

app.get('/', function(req, res) {
   res.send('id: ' + req.params.id + ' and name: ' + req.params.name);
});
var things = require('./things/things.js');

//both index.js and things.js should be in same directory
app.use('/things', things);
//Simple request time logger
app.use('/',function(req, res, next){
   console.log("A new request received at " + Date.now());

   //This function call is very important. It tells that more processing is
   //required for the current request and is in the next middleware
   //function/route handler.
   next();
});

app.listen(3000);

I am learning about middleware functions and am trying to show a console.log message when I go to localhost:3000, but nothing shows up in my console, what am I missing here?

4 Answers

The correct 'id' and 'name' of the parameters in get is like this

app.get('/:id/:name', function(req, res) {
   res.send('id: ' + req.params.id + ' and name: ' + req.params.name);
});
Related