express-readbody
Advanced tools
Comparing version 1.0.0 to 1.1.0
module.exports = function readBody (req) { | ||
if (typeof req !== 'object' || typeof req.on !== 'function') { | ||
throw new TypeError(`expected an instance of stream.Readable, got ${typeof req} instead`); | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -10,4 +13,4 @@ let body = ''; | ||
req.on('end', () => resolve(body)); | ||
req.on('error', (e) => reject(e)); | ||
req.on('error', e => reject(e)); | ||
}); | ||
}; |
{ | ||
"name": "express-readbody", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Convenience function for easier reading of request data", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "ava test.js" | ||
}, | ||
@@ -23,3 +23,15 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/janis-kra/express-readbody#readme" | ||
"homepage": "https://github.com/janis-kra/express-readbody#readme", | ||
"devDpendencies": { | ||
"eslint": "^3.13.1", | ||
"eslint-config-janiskra": "^1.9.1" | ||
}, | ||
"engines": { | ||
"node": ">6.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.17.0", | ||
"eslint": "^3.13.1", | ||
"eslint-config-janiskra": "^1.10.0" | ||
} | ||
} |
# express-readbody | ||
Convenience function for easier reading of request data | ||
Convenience function for easier reading of request data. | ||
## Why? | ||
Use this for a small project in which you just want the payload of a handful of POST or PUT requests to be read as a string. | ||
For anything more complex or big, you probably want to use the excellent [body-parser middleware](https://www.npmjs.com/package/body-parser) or something similar. | ||
## Installation | ||
``` | ||
npm install --save express-readbody | ||
``` | ||
## Usage | ||
@@ -8,2 +20,3 @@ | ||
const server = require('express')(); | ||
const readBody = require('express-readbody'); | ||
@@ -10,0 +23,0 @@ server.post('/hello', (req, res) => { |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
128406
8
37
0
26
0
3