Basic Node and Express - Implement a Root-Level Request Logger Middleware

Tell us what’s happening:
I keep getting ‘SyntaxError: missing ) after argument list’ on the console

my code:
let express = require(‘express’);
let app = express();

app.use((req, res, next) => {

 let string = `${req.method} ${req.path} - ${req.ip}`

console.log(string)

next();

})

Your project link(s)

solution: boilerplate-express-6 - Nix (beta) Repl - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: Basic Node and Express - Implement a Root-Level Request Logger Middleware

Link to the challenge:

Oh, I have passed the JSON test.

Its the Implement a Root-Level Request Logger Middleware that I’m having issues with.

I have added different codes, including:

app.use((req, res, next) =>

console.log(req.method + " " + req.path + " - " + req.ip );

next();

});

But nothing seems to work

I don’t know what code you wrote to pass the other challenges before this one, but the following code (in app version you supplied in your original post) is causing your issue.

const mySecret = process.env['MESSAGE_STYLE']
app.get("/json", (req, res) => {
  if(process.env.MESSAGE_STYLE === 'uppercase'){
    res.json("message": "HELLO JSON")
  }else{
    res.json(message: "Hello json")
  }
  });

You can comment the following code and it will still error out in the Node console.

app.use((req, res, next) => {
  
     let string = `${req.method} ${req.path} - ${req.ip}`
 console.log(string) 
  
    next();
})

The code you wrote at the top would have also shown the same error message if you used it on any of the previous challenges of this section.

Please, how can I correct this?

This is the key question. Try answering it and then re-analyze your code to see what is wrong.

1 Like

I corrected the code as thus:

const mySecret = process.env[‘MESSAGE_STYLE’]
app.get(“/json”, (req, res) => {
let msg = process.env.MESSAGE_STYLE===“uppercase”?“HELLO JSON”:“Hello json”;
});

And the syntax error is off on the console.

I just need the GET / json - ::ffff… but I’ll figure it out.

Thank you :+1:

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