Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
express-response-formatter
Advanced tools
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/aofleejay/express-response-formatter/blob/master/LICENSE.md) [![npm](https://img.shields.io/npm/v/express-response-formatter.svg)](https://www.npmjs.com/package/expr
Better way to format Express response
npm install express-response-formatter --save
Example usage
const app = require('express')()
const responseEnhancer = require('express-response-formatter')
// Add formatter functions to "res" object via "responseEnhancer()"
app.use(responseEnhancer())
app.get('/success', (req, res) => {
const users = [{ name: 'Dana Kennedy' }, { name: 'Warren Young' }]
// It's enhance "res" with "formatter" which contain formatter functions
res.formatter.ok(users)
})
app.listen(3000, () => console.log('Start at http://localhost:3000'))
Result
HTTP/1.1 200 Ok
{
"data": [
{
"name": "Dana Kennedy"
},
{
"name": "Warren Young"
}
]
}
200 OK with "meta field"
app.get('/success-with-meta', (req, res) => {
const users = [{ name: 'Dana Kennedy' }, { name: 'Warren Young' }]
const meta = {
total: 2,
limit: 10,
offset: 0,
}
res.formatter.ok(users, meta)
})
HTTP/1.1 200 Ok
{
"meta": {
"total": 2,
"limit": 10,
"offset": 0,
},
"data": [
{
"name": "Dana Kennedy"
},
{
"name": "Warren Young"
}
]
}
400 Bad Request with "multiple errors"
app.get('/bad-request', (req, res) => {
const errors = [
{ detail: 'Field id is required.' },
{ detail: 'Field foo is required.' },
]
res.formatter.badRequest(errors)
})
HTTP/1.1 400 Bad Request
{
"errors": [
{
"detail": "Field id is required."
},
{
"detail": "Field foo is required."
}
]
}
METHOD | STATUS CODE |
---|---|
res.formatter.ok(data, meta?) | 200 |
res.formatter.created(data, meta?) | 201 |
res.formatter.accepted(data, meta?) | 202 |
res.formatter.noContent(data, meta?) | 204 |
res.formatter.badRequest(errors) | 400 |
res.formatter.unauthorized(errors) | 401 |
res.formatter.forbidden(errors) | 403 |
res.formatter.notFound(errors) | 404 |
res.formatter.methodNotAllowed(errors) | 405 |
res.formatter.timeout(errors) | 408 |
res.formatter.conflict(errors) | 409 |
res.formatter.unprocess(errors) | 422 |
res.formatter.tooManyRequests(errors) | 429 |
res.formatter.serverError(errors) | 500 |
res.formatter.badGateway(errors) | 502 |
res.formatter.serviceUnavailable(errors) | 503 |
res.formatter.gatewayTimeout(errors) | 504 |
FAQs
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/aofleejay/express-response-formatter/blob/master/LICENSE.md) [![npm](https://img.shields.io/npm/v/express-response-formatter.svg)](https://www.npmjs.com/package/expr
The npm package express-response-formatter receives a total of 464 weekly downloads. As such, express-response-formatter popularity was classified as not popular.
We found that express-response-formatter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.