Skip to content

docs(res.sendFile): use res.status() in the example - #7534

Open
johnnyhuirilef wants to merge 1 commit into
expressjs:masterfrom
johnnyhuirilef:docs/sendfile-example-status
Open

johnnyhuirilef wants to merge 1 commit into
expressjs:masterfrom
johnnyhuirilef:docs/sendfile-example-status

Conversation

@johnnyhuirilef

Copy link
Copy Markdown

Hi! 🙂 The JSDoc example of res.sendFile calls res.send(403, 'Sorry! you can\'t see that.'). Express 5.0.0-alpha.6 removed the res.send(status, body) signature (see History.md), so this code sends a 200 response with the body 403:

const express = require('express')
const app = express()

app.get('/', (req, res) => res.send(403, 'Sorry! you can\'t see that.'))

const server = app.listen(0, async () => {
  const res = await fetch(`http://localhost:${server.address().port}`)
  console.log(res.status, await res.text())
  server.close()
})

Output on 5.3.0 (Node 24.21.0):

200 403

This change uses res.status(403).send(...) in the example, the replacement that History.md gives for the removed signature. With this change in the script, it prints 403 Sorry! you can't see that.

Only the JSDoc comment changes. No code runs differently.

Happy to change anything you prefer 🙌

The example called res.send(403, body). Express 5 removed this signature, so the example sent a 200 response with the body "403". Use res.status(403).send(body).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentations issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants