This library exports a middleware to append to your expressjs app. The exported middleware allows you to get response body in an easy way.
- the library is agnostic from any dependency (except, of course, expressjs). The middleware can be plugged into your express middlewares chain (e.g. you don't have to install morgan in your app)
- the middleware can be used both synchronously and asynchronously
- the middleware works even if the body response is compressed with compression library
import bodyResponseMiddleware from 'express-body-response-middleware';
const app = express();
const onSuccess = (body: string) => console.log(body);
const onError = (err: Error) => { throw err };
app.use(bodyResponseMiddleware(onSuccess, onError));
This is a Node.js module available through the npm registry. Installation is done using the npm install
command
npm install --save express-body-response-middleware
In your app.ts
file you have to define onSuccess
and onError
functions, then append the middleware to you expressjs app.
import bodyResponseMiddleware from 'express-body-response-middleware';
const app = express();
const onSuccess = (body: string) => console.log(body);
const onError = (err: Error) => { throw err };
app.use(bodyResponseMiddleware(onSuccess, onError));
import bodyResponseMiddleware from 'express-body-response-middleware';
import fs from "fs";
const app = express();
const onSuccess = (body: string) => fs.writeFileSync("body-response.log", body);
const onError = (err: Error) => { throw err };
app.use(bodyResponseMiddleware(onSuccess, onError));
MIT