FG
💻 Software🌐 Web & Full-Stack

Deprecate res.send(status, body) format

Fresh3 days ago
Mar 14, 20260 views
Confidence Score55%
55%

Problem

This is a discussion regarding the possibility of deprecating `res.send(status, body)` and other methods (`json`, `jsonp` to name some) that do the same thing, where there is an optional first status argument. Specifically, deprecating the optional `status` as a first argument thing. /cc @defunctzombie

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Deprecate Optional Status Argument in res.send() Method

Medium Risk

The `res.send(status, body)` method in Express allows an optional first argument for status codes, which can lead to confusion and inconsistent usage patterns. This flexibility can result in bugs where the status code is unintentionally omitted or misused, particularly in larger codebases. Deprecating this feature will encourage a more consistent API usage and improve code readability.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify Usage of res.send with Status Argument

    Scan the codebase for instances of `res.send(status, body)` to identify where the optional status argument is being used. This can be done using a code search tool or a simple regex search.

    bash
    grep -r 'res.send(' . | grep -E 'res.send\s*\(\s*\d{3},'
  2. 2

    Update Code to Use res.status() Method

    Refactor the identified instances to use the `res.status(status).send(body)` method instead. This change will make it explicit that the status code is being set before sending the response.

    javascript
    res.status(200).send('Success');
  3. 3

    Add Deprecation Warning in Documentation

    Update the official documentation to include a deprecation notice for the `res.send(status, body)` format. Clearly state that this feature will be removed in future versions and provide guidance on the preferred usage.

    javascript
    // Deprecated: res.send(status, body)
    // Use: res.status(status).send(body)
  4. 4

    Implement Linting Rules for Codebase

    Set up ESLint or a similar tool to enforce the new usage pattern across the codebase. Create custom rules that will flag any usage of `res.send` with a status argument as a warning or error.

    json
    {
      "rules": {
        "no-deprecated-res-send": "error"
      }
    }
  5. 5

    Monitor and Review Code Changes

    After implementing the changes, monitor the codebase for adherence to the new standards. Conduct code reviews to ensure that no new instances of the deprecated method are introduced.

    javascript
    // Review PRs for usage of res.send with status argument

Validation

Confirm that all instances of `res.send(status, body)` have been refactored to `res.status(status).send(body)` and that the linter is flagging any new occurrences. Check the documentation for the updated deprecation notice.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

expressnode.jsapideprecate5.x