-2

My code goes like this:

    app.get("/:pageName",function(req,res){
  const listName=req.params.pageName;
  console.log(listName)
  const list = new List({name:listName,items:defaultItems});
  list.save();
});

If I only typed in the URL bar in the browser "http://localhost:3000/" does the app execute the previous code or not?

If it does, how can I tell it not to?

Yous k
  • 19
  • 3
  • Did you try it? What happened? – jonrsharpe Jul 05 '21 at 07:40
  • of course i tried it , it is executing the code inside without me typing anything after the "http://localhost:3000/" i will edit my full code in the question . also i read the docs they didnt mention anything regarding my problem. – Yous k Jul 05 '21 at 07:54

1 Answers1

2

The short answer is no - express will only resolve a non-empty value as a path parameter, unless you use some wildcard (e.g, ?) to make it optional.

Mureinik
  • 297,002
  • 52
  • 306
  • 350