Node js middleware

Tell us what’s happening:
this is my code for middle ware it is not accepting

var express = require('express');
var app = express();
var router = express.Router()
app.use(function middleware(req, res, next) {
  var string = req.method + " " + req.path + " - " + req.ip;
  console.log(string);
  // Call the next function in line:
  next();
});
console.log("Hello World");
app.use(express.static('public'))

app.get('/',function(req,res){
res.sendFile('views/index.html' , { root : __dirname});
});

app.get('/json', function(req, res) {
  if (process.env.MESSAGE_STYLE == "uppercase") {
    res.json({"message": "Hello json".toUpperCase()})
  }else{
    res.json({"message": "Hello json"})

  }
})

module.exports = app;

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Implement a Root-Level Request Logger Middleware

Link to the challenge:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.