# express-jsonx

> An opinionated express middleware just extend res.json.

Latest version **0.0.1** (published 2019-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-jsonx
pnpm add express-jsonx
yarn add express-jsonx
bun add express-jsonx
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2019-07-22 |
| First published | 2019-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xovel |
| Maintainers | xovel |
| Keywords | express, middleware |

## Links

- npm: https://www.npmjs.com/package/express-jsonx
- Repository: https://github.com/xovel/express-jsonx
- Homepage: https://github.com/xovel/express-jsonx#readme
- Issues: https://github.com/xovel/express-jsonx/issues
- npm.io page: https://npm.io/package/express-jsonx

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2019-07-22

## README

# express-jsonx

An opinionated express middleware just extend res.json.

## Install

```bash
npm install express-jsonx
```

## Usage

```js
const express = require('express')
const jsonx = require('express-jsonx')

const app = express()
app.use(jsonx())

app.get('/', function (req, res) {
  res.jsonx(1, 'Hi~')
})
```

- `res.jsonx(1)` <=> `res.json({code: 0, data: 1})`
- `res.jsonx({demo: true})` <=> `res.json({code: 0, data: {demo: true}})`
- `res.jsonx(1, 'text')` <=> `res.json({code: 1, data: 'text'})`
- `res.jsonx(-1, '', 'fail')` <=> `res.json({code: -1, data: '', msg: 'fail'})`

## Options

```js
app.use(jsonx(options))
```

| name | type | default | note |
| ---- | ---- | ------- | ---- |
| codeKey | string | `code` | key of code |
| dataKey | string | `data` | key of data |
| msgKey | string | `msg` | key of message |
| defaultCode | number | `0` | default code |

## License

MIT(./LICENSE)

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