![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
joi4express
Advanced tools
Joiexpress validator
const express = require('express')
const app = express()
const joi4express = require('joi4express')
const helloWorld = {
handler: (req, res) => {
res.send('Hello-world !')
},
validate: {
query: Joi.object({
param1: Joi.string()
}),
params: Joi.object({
param1: Joi.string()
}),
body: {
param1: Joi.array().items({
param2: Joi.string()
})
},
headers: Joi.object({
param1: Joi.string()
}),
},
response: {
schema: Joi.object({
param1: Joi.string()
}),
status: {
204: Joi.object({
param2: Joi.string()
}),
404: Joi.object({
error: 'Failure'
})
}
}
}
app.get('/', joi4express(helloWorld))
app.listen(port, function () {
console.log(`Example app listening on port ${port} !`)
})
The library also accepts a Joi Options object, and a Custom Joi Error Formatting function.
In the following example, double quotes will be removed due to the custom error formatting function.
const customJoiErrorFormatFcn = (e) => {
const message = e.message.replace(/"/g, '')
const details = e.details.map(detail => ({
...detail,
message: detail.message.replace(/"/g, '')
}))
return {
message,
details
}
}
const joiOptions = null // Or some desired options
app.get('/', joi4express(helloWorld, joiOptions, customJoiErrorFormatFcn))
Any custom formatting function must return an object of the form:
{
message: 'a message string',
details: [
{
// Joi Error Details Object
}
]
}
If the user-defined formatting function fails, then the original message/details will be returned (as if the function was never defined in the first place)
npm install joi4express --save
Tests are written with mocha/chai.
$ npm test
FAQs
Joi validator for express, validates the request and the reponse
The npm package joi4express receives a total of 5 weekly downloads. As such, joi4express popularity was classified as not popular.
We found that joi4express 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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.