# morgan-res-body

> A simple morgan plugin for response body

Latest version **1.0.2** (published 2022-11-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install morgan-res-body
pnpm add morgan-res-body
yarn add morgan-res-body
bun add morgan-res-body
```

## 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.0.2 |
| Published | 2022-11-22 |
| First published | 2022-10-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | fwg |
| Maintainers | adf0001 |
| Keywords | morgan, response, body |

## Links

- npm: https://www.npmjs.com/package/morgan-res-body
- Repository: https://github.com/adf0001/morgan-res-body
- Homepage: https://github.com/adf0001/morgan-res-body#readme
- Issues: https://github.com/adf0001/morgan-res-body/issues
- npm.io page: https://npm.io/package/morgan-res-body

## Recent versions

- 1.0.2 (latest) — 2022-11-22
- 1.0.1 — 2022-10-09
- 1.0.0 — 2022-10-07

## README

# morgan-res-body
A simple morgan plugin for response body

# Install
```
npm install morgan-res-body
```

# Usage & Api
```javascript

var express = require('express');
var morgan = require('morgan');
var morgan_res_body = require('morgan-res-body');

var app = express();

/*
.tokenFunction

A default token function in following condition,
	* response body buffer named "bodyBuffer"
	* normal statusCode less than 400
	* convert to text
	* prifixed with line-break and "Res-body: "
	* utf8

In any other condition, re-write your own token function. 
*/
morgan.token("res-body",morgan_res_body.tokenFunction);		//register the token
//morgan.token("res-body",(req, res)=>{...});		//or self-defined token function

var morgan_logger = morgan( '... :req-body :res-body ...', ... );	//use the token
app.use(morgan_logger);		//add morgan middleware

/*
.createMiddleware(options)

create a middleware function for express
	options
		skip
			a function like (req, res)=>{...},
			return true to indicate to skip the request.

		bufferName
			a property name for saving body buffer in res, default "bodyBuffer".

*/
app.use(morgan_res_body.createMiddleware());	//add middleware for res-body


/*
More, how about the request body, the ":req-body"?

just copy the following code and change it as you like.
*/
morgan.token("req-body", (req, res) => {
	if (req.body && res.statusCode < 400) {
		return "\nReq-body: " + JSON.stringify(req.body);
	}
});

```

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