
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
express-response-formatter
Advanced tools
[](https://github.com/aofleejay/express-response-formatter/blob/master/LICENSE.md) [](https://www.npmjs.com/package/expr
Better way to format Express response
res.formatter.ok
for 200 ok or res.formatter.badRequest
for 400 bad request.success
and error
.
2xx, 3xx
return response under object key data
.4xx, 5xx
return response under object key error
.meta
object key.npm install express-response-formatter --save
Response for 200 Ok.
import app from 'express'
import { responseEnhancer } from 'express-response-formatter'
const app = express()
// 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"
}
]
}
Response for 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"
}
]
}
Response for 400 Bad Request with "error"
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
{
"error": [
{
"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, meta) | 400 |
res.formatter.unauthorized(errors, meta) | 401 |
res.formatter.forbidden(errors, meta) | 403 |
res.formatter.notFound(errors, meta) | 404 |
res.formatter.methodNotAllowed(errors, meta) | 405 |
res.formatter.timeout(errors, meta) | 408 |
res.formatter.conflict(errors, meta) | 409 |
res.formatter.unprocess(errors, meta) | 422 |
res.formatter.tooManyRequests(errors, meta) | 429 |
res.formatter.serverError(errors, meta) | 500 |
res.formatter.badGateway(errors, meta) | 502 |
res.formatter.serviceUnavailable(errors, meta) | 503 |
res.formatter.gatewayTimeout(errors, meta) | 504 |
[2.0.2] - 2020-08-12
FAQs
[](https://github.com/aofleejay/express-response-formatter/blob/master/LICENSE.md) [](https://www.npmjs.com/package/expr
The npm package express-response-formatter receives a total of 262 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
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.