> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP Classes with new Keyword

> Add new keyword when instantiating HTTP classes like OutgoingMessage and ServerResponse (DEP0195)

This recipe ensures HTTP classes like `OutgoingMessage`, `ServerResponse`, `IncomingMessage`, and `ClientRequest` are properly instantiated with the `new` keyword.

## Deprecation

Node.js deprecated calling HTTP constructors without the `new` keyword. Classes must be instantiated with `new`.

See [DEP0195](https://nodejs.org/api/deprecations.html#DEP0195) for more details.

## Usage

Run this codemod with:

```bash theme={null}
npx codemod nodejs/http-classes-with-new
```

## Before/After

```diff theme={null}
  // import { IncomingMessage, ClientRequest } from "node:http";
  // const http = require("node:http");

- const message = http.OutgoingMessage();
+ const message = new http.OutgoingMessage();
- const response = http.ServerResponse(socket);
+ const response = new http.ServerResponse(socket);

- const incoming = IncomingMessage(socket);
+ const incoming = new IncomingMessage(socket);
- const request = ClientRequest(options);
+ const request = new ClientRequest(options);
```

## What It Does

* Adds `new` keyword before `OutgoingMessage()`, `ServerResponse()`, `IncomingMessage()`, and `ClientRequest()` calls
* Works with both direct imports and namespace imports (e.g., `http.OutgoingMessage()`)
* Handles CommonJS and ESM module patterns

## Affected Classes

The following HTTP classes are updated:

* `OutgoingMessage`
* `ServerResponse`
* `IncomingMessage`
* `ClientRequest`

<Tip>
  Modern JavaScript requires all classes to be instantiated with the `new` keyword. This deprecation aligns Node.js HTTP classes with standard JavaScript class syntax.
</Tip>
