RangeError: Invalid status code: 0

I had the same problem which I solved by using:

res.send('0')

instead of

res.send(0)

I had a similar error message just now and managed to solve the problem by changing:

res.status(statusCode);

to:

if (statusCode >= 100 && statusCode < 600)
  res.status(statusCode);
else
  res.status(500);

or just:

res.status(statusCode >= 100 && statusCode < 600 ? err.code : 500);

I.e. make sure you aren't trying to set an invalid HTTP status code somewhere.

It's likely this is the issue but it looks like you've accidentally duplicated the app.js code instead of pasting the edit.js code in the question.


This case also happen when we have validation error on form save and we are using res.redirect instead of res.render method

for example-

Please Use

res.render('users/add', {
    countries: countries
});

instead of (it's wrong statement for node)

res.redirect('/users/add', {
    countries: countries
});