Express warns that res.send(status) is deprecated
express deprecated res.send(status): Use res.sendStatus(status) insteadShort answer
Express 4 prints this warning when a number is passed to res.send() as a status code. Express 5 removed that signature. Replace res.send(404) with res.sendStatus(404), or res.status(404).send('text') when you want your own body. If the number is meant as the body, quote it. Find the call site with node --trace-deprecation.
Fix it fast
1Find out which cause you have
Run the app with Node's trace flag. The warning then prints the full stack, and its first lines name the file and line that made the call. By default it shows only the location of the call, once per call site.
node --trace-deprecation server.js2Match what you see, then jump to its fix
- 1
The warning text itself, and the stack points at a line like res.send(404)A status number is passed to res.send()Fix - 2
The call is res.send(count) or res.send(42), and the client expected the number back as dataA number was meant to be the response bodyFix - 3
Calls such as res.send(404, 'Not found') or res.json(obj, 201)Status and body are passed to the same call in the old argument orderFix - 4
The stack from --trace-deprecation points into node_modulesA dependency makes the call, not your own codeFix
- 1
What does the error look like?
express deprecated res.send(status): Use res.sendStatus(status) insteadThe warning prints once per call site, so only the first request through each line shows itAfter upgrading to Express 5, res.send(200) and res.json(obj, 201) no longer behave as they did
Cause 1 of 4
A status number is passed to res.send()
1Check
Search your own code for res.send() called with a three-digit number and nothing else.
grep -rnE "res\.send\([0-9]{3}\)" --include="*.js" --exclude-dir=node_modules .2Fix
Use res.sendStatus(), which sets the status and sends its text (Not Found for 404, and so on). If you want your own body next to the status, chain res.status() instead.
res.sendStatus(404);
// or, with your own body:
res.status(404).send('No such invoice');3Verify
The response carries the status you chose, and the console no longer prints the warning for that line.
curl -i http://localhost:3000/missingConfirmed by expressjs.com
Cause 2 of 4
A number was meant to be the response body
1Check
Express 4 reads a number given to res.send() as a status code; Express 5 does not support that signature at all. Look at what the argument stands for: a count, an id or a status.
grep -rn "res.send(" --include="*.js" --exclude-dir=node_modules .2Fix
Quote the number to turn it into a string, as the Express 5 migration guide says, so Express does not take it for the old signature.
res.send(String(count));
// or a literal: res.send('42');3Verify
The body of the response is the number as text.
curl -s http://localhost:3000/countConfirmed by expressjs.com
Cause 3 of 4
Status and body are passed to the same call in the old argument order
1Check
Express 4.7 deprecated res.send(status, body), and the Express 5 guide lists res.json(obj, status) as no longer supported. Search for both shapes.
grep -rnE "res\.send\([0-9]{3}," --include="*.js" --exclude-dir=node_modules .
grep -rnE "res\.json\(.+, *[0-9]{3}\)" --include="*.js" --exclude-dir=node_modules .2Fix
Set the status first with res.status(), then chain the body method.
res.status(404).send('Not found');
res.status(201).json({ name: 'Ruben' });3Verify
Status and body both arrive as written.
curl -i -X POST http://localhost:3000/users -H 'Content-Type: application/json' -d '{"name":"Ruben"}'Confirmed by github.com
Cause 4 of 4
A dependency makes the call, not your own code
1Check
The warning names the file and line that called the deprecated function. When that path is inside node_modules, the old call form is in a package, and editing your own routes will not remove the warning.
node --trace-deprecation server.js 2>&1 | grep node_modules
npm ls express2Fix
Update the package that owns the call, or replace it. Do not edit files under node_modules: the change disappears on the next install.
npm update my-middleware-package3Verify
Start the app again with the trace flag and send the request that printed the warning.
node --trace-deprecation server.jsConfirmed by github.com
How do I stop it coming back?
- Always set the status with res.status(code) and finish with send(), json() or end(), never with the number inside send().
- Start tests with node --trace-deprecation so new warnings show up before they become errors in Express 5.
- Read the removed-methods list of the Express 5 migration guide before you upgrade, and grep for each item.
- Keep middleware packages up to date, since the old call forms in them cause the same warning.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Express crashes with RangeError: Invalid status code: undefined
RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined
Node throws this when a response is given a status that is not a number from 100 to 999.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fix