parse-body.ts
This file
Path
test/helpers/parse-body.ts
9 lines · 321 bytes · TypeScript
Last changed by
Require Node.js 22Sindre Sorhusbefore adoptionf1da0fc
History of this fileTake it
12345678910import {text} from 'node:stream/consumers';import type {Request} from 'express';
export const parseJsonBody = async <T = any>(request: Request): Promise<T> => { const body = await text(request); return JSON.parse(body) as T;};
export const parseRawBody = async (request: Request): Promise<string> => text(request);