Skip to content

Missing reference (and types) for response.socket.server #47148

Description

@tapplav0

Affected URL(s)

https://nodejs.org/dist/latest-v18.x/docs/api/http.html#responsesocket

Description of the problem

There seems to have been a missing property in the API reference (and @types/node typings) regarding the server property of a ServerResponse instance.
I have seen about it multiple times in articles or videos, for example to set up Socket.io in Next.js or a WebSocket module in Nuxt.

Here is a simple snippet that allows to access the server property:

const { createServer } = require('http');

createServer((req, res) => {
    console.log(res.socket.server); // Logs the server instance
});

I don't know if that property is supposed not to be used or if it is just missing from the API references, but it seems like the common way to 'plug in' WebSocket servers onto frameworks that don't directly provide a way to do so.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.httpIssues and PRs related to the http subsystem.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions