Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Empty URL parameters can be handled in Node.js using Express by checking if the parameter exists and then assigning a default value if it is empty. Here is an example:

app.get('/users/:id', (req, res) => {
  const id = req.params.id || 'default';
  // handle the ID
});

In this example, if the id parameter in the URL is empty or not provided, it will default to the string 'default'. This way, we can handle the scenario where the parameter is empty without causing errors in our code.