express deprecated and RangeError [ERR_HTTP_INVALID_STATUS_CODE] in React Project

91 Views Asked by At

With my React cruise ship project, on my reviews-part branch I am getting the following error when running npm run dev for the localhost.

NPM Run Dev Error for ShipsList on Command Line

It says that express is deprecated , what does this mean ? It is also pointing to my ships route

and on my localhost these are the errors
enter image description here

I need help to understand why these errors are happening. If anyone has any suggestions that may help, that will be much appreciated.

1

There are 1 best solutions below

0
robertklep On

The error doesn't say that Express is deprecated, it says that res.send(status, body) is deprecated. More specifically, it means that res.send() should only be passed one argument.

In your code, you're using two arguments:

res.status(500).send('something went wrong', err)

Express is trying to parse the first argument ('something went wrong') as an HTTP status code, which it obviously isn't, hence the ERR_HTTP_INVALID_STATUS_CODE error.

One solution would be to add the error message to the string.

res.status(500).send(`something went wrong: ${ err.message }`)