# jai-body-parser

> Powerful Node.js module/package for parsing request body

Latest version **1.1.45** (published 2024-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install jai-body-parser
pnpm add jai-body-parser
yarn add jai-body-parser
bun add jai-body-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.45 |
| Published | 2024-09-01 |
| First published | 2022-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Harpal Singh |
| Maintainers | singh_harpal |
| Keywords | body parser, body parser, nodejs, request body, body, middleware, request handler, jai.js, jai, jai-body-parser, body-parser, bodyparser, body parser middleware, body-parser middleware, bodyparser middleware, body parser nodejs, body-parser nodejs, bodyparser nodejs, body parser request, body-parser request, bodyparser request, body parser request handler, body-parser request handler, bodyparser request handler, body parser request handler middleware, body-parser request handler middleware, bodyparser request handler middleware, body parser request handler nodejs, http request, http, http request body, http request body parser, http request parser, http request middleware, http request handler, http request body handler, http request body middleware, http request body parser middleware |

## Links

- npm: https://www.npmjs.com/package/jai-body-parser
- Repository: https://github.com/jaijs/jai-body-parser
- Homepage: https://github.com/jaijs
- Issues: https://github.com/jaijs/jai-body-parser/issues
- npm.io page: https://npm.io/package/jai-body-parser

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.1.45 (latest) — 2024-09-01
- 1.1.41 — 2024-08-31
- 1.1.4 — 2024-07-02
- 1.1.3 — 2023-07-16
- 1.1.1 — 2022-08-27
- 1.0.1 — 2022-07-29

## README

# Jai Body Parser
Simple and fast Node.js module for parsing Http request body. Part of Jai.js ecosystem. Built without any third part dependency.
Jai body parser is a middleware for node.js that parses incoming request body in a middleware before your application’s request handlers are called.
Allowed content-types  'application/x-www-form-urlencoded', 'text/plain', 'application/json', 'application/javascript','application/xml'.

---
[![Twitter Follow](https://img.shields.io/twitter/follow/hsk11dev?label=Follow)](https://twitter.com/intent/follow?screen_name=hsk11dev)
[![Linkedin: Harpal Singh](https://img.shields.io/badge/-hsk11-blue?style=flat-square&logo=Linkedin&logoColor=white&link=https://www.linkedin.com/in/hsk11)](https://www.linkedin.com/in/hsk11/)
[![GitHub followers](https://img.shields.io/github/followers/hsk11?label=Follow&style=social)](https://github.com/hsk11)
---

## Features

- Easy Setup
- Config the request body size
- Config specific request methods to implement/use
- Config request header content-types to use
- option to save raw body or payload
- Can be used with any framework





## Installation

Install my-project with npm

```bash
  npm install jai-body-parser
```

### Usage / Examples

```javascript
// JAI SERVER

const jaiServer = require('jai-server');
const jaiBodyParser = require('jai-body-parser');

const app = jaiServer();
const port = 1111;
app.use(jaiBodyParser(/* options */));
app.post('*', (req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ body: req.body }));
});


app.listen(port, () => {
  console.log(`Server listening on http://localhost:${port}/ ...`);
});


// Express

const express = require('express');
const jaiBodyParser = require('jai-body-parser');

const app = express();
const port = 1111;
app.use(jaiBodyParser(/* options */));
app.post('*', (req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ body: req.body }));
});


app.listen(port, () => {
  console.log(`Server listening on http://localhost:${port}/ ...`);
});


//  OR Http

const http = require('http');
const jaiBodyParser = require('jai-body-parser');

const server = http.createServer(async (req, res) => {
  jaiBodyParser(/* options */)(req, res, (err) => {
    if (err) {
      res.writeHead(200, { 'Content-Type': 'application/json' });
      return res.end(JSON.stringify({ Error: err.stack }));
    }
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ body: req.body }));
  });
});

server.listen(1111, () => {
  console.log('Server listening on http://localhost:1111/ ...');
});


```

## API Reference

### Options
```javascript
 {
    limit: 11111, // in kb
    shouldSaveRawBody: false,
    allowedMethods: [],
    allowedContentTypes:['application/x-www-form-urlencoded' 'text/plain',
'application/json', 'application/javascript', 'application/xml'],
    parseNumbers: true
  }
```

| Parameter | Type     | Description                |
| :-------- | :------- | :------------------------- |
| `limit` | `integer` |  size in kb, default: 100 (100kb)|
| `shouldSaveRawBody` | `boolean` | should save raw body, default: false. useful when authenticating webhook responses|
| `allowedMethods` | `array` |  array of allowed http methods, default: ['post', 'put', 'patch']|
| `allowedContentTypes` | `array` |  array of allowed Content types, default: `['application/x-www-form-urlencoded' 'text/plain','application/json', 'application/javascript', 'application/xml']`|
| `parseNumbers` | `boolean` |  parse numbers from body text, default: true,

---
_Source: https://npm.io/package/jai-body-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
