Does anyone know what’s wrong with my code? I’m stuck on this challenge for hours and the error is always the same: “Root level logger middleware should be active”.
var express = require('express');
var path = require('path');
var app = express();
app.get("/", function(req, res) {
res.sendFile(__dirname+ "/views/index.html");
})
app.use("/public",express.static(__dirname + "/public"))
// 5 & 6 - Serve JSON on a Specific Route
app.get('/json', (req, res) => {
const mySecret = process.env['MESSAGE_STYLE']
if (mySecret === "uppercase"){
res.json({
"message": "HELLO JSON"
})
} else {
res.json({
"message": "Hello json"
})
}
})
//7 - Implement a Root-Level Request Logger Middleware
app.use((req, res, next) => {
console.log(req.method + " " + req.path + " - " + req.ip);
next();
})
module.exports = app;