• Version 2.4.1
  • Published
  • 22.8 kB
  • 4 dependencies
  • MIT license


npm i raw-body
yarn add raw-body
pnpm add raw-body


Get and validate the raw body of a readable stream.



function getRawBody

getRawBody: {
(stream: any, callback: (err: getRawBody.RawBodyError, body: any) => void): void;
stream: any,
| getRawBody.Encoding
| (getRawBody.Options & { encoding: getRawBody.Encoding }),
callback: (err: getRawBody.RawBodyError, body: string) => void
): void;
stream: any,
options: getRawBody.Options,
callback: (err: getRawBody.RawBodyError, body: any) => void
): void;
stream: any,
| getRawBody.Encoding
| (getRawBody.Options & { encoding: getRawBody.Encoding })
): Promise<string>;
(stream: any, options?: getRawBody.Options): Promise<any>;
  • Gets the entire buffer of a stream either as a Buffer or a string. Validates the stream's length against an expected length and maximum limit. Ideal for parsing request bodies.


interface Options

interface Options {}

    property encoding

    encoding?: Encoding | null;
    • The encoding to use to decode the body into a string. By default, a Buffer instance will be returned when no encoding is specified. Most likely, you want utf-8, so setting encoding to true will decode as utf-8. You can use any type of encoding supported by iconv-lite.

    property length

    length?: number | string | null;
    • The expected length of the stream.

    property limit

    limit?: number | string | null;
    • The byte limit of the body. This is the number of bytes or any string format supported by bytes, for example 1000, '500kb' or '3mb'.

    interface RawBodyError

    interface RawBodyError extends Error {}

      property encoding

      encoding?: string;
      • The encoding.

      property expected

      expected?: number;

        property length

        length?: number;
        • The expected length of the stream.

        property limit

        limit?: number;
        • The limit in bytes.

        property received

        received?: number;
        • The received bytes.

        property status

        status: number;
        • The corresponding status code for the error.

        property statusCode

        statusCode: number;

          property type

          type: string;
          • The error type.

          Type Aliases

          type Encoding

          type Encoding = string | true;

            Package Files (1)

            Dependencies (4)

            Dev Dependencies (12)

            Peer Dependencies (0)

            No peer dependencies.


            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/raw-body.

            • Markdown
            • HTML
              <a href="https://www.jsdocs.io/package/raw-body"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>