Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

joi-express

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-express

Simple validation middleware for express using the joi validation suite.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

joi-express

Build Status Coverage Status

Simple validation middleware for express using the Joi validation suite.

Installation

npm install joi-express

Dependencies

npm install joi

Usage


var Express = require('express');
var BodyParser = require('body-parser');
var ExpressJoi = require('joi-express');
var Joi = require('joi');

var app = Express();
app.use(BodyParser.json());

// Use Joi to create your schemas
var querySchema = {
    query: {
        limit: Joi.number().default(10).min(10).max(100),
        offset: Joi.number().default(10).min(10).max(100)
    },
    headers: {
        authorization: Joi.string().required()
    }
};

// Attach the validator like other middleware
app.get('/', expressJoi(querySchema), function (req, res, next) {
   	// do something with req.query.limit & req.query.offset
    ...
});

// Use Joi to create your schemas
var bodySchema = {
    body: {
        name: Joi.string().required()
    }
};

// Attach the validator like other middleware
app.post('/', expressJoi(bodySchema), function (req, res, next) {
	// do something with req.body;
    ...
});

// Example error handler
app.use(function (err, req, res, next) {
    if (err.isBoom) {
         return res.status(err.output.statusCode).json(err.output.payload);
    }
});



app.listen(8080);

If a validation error occurs it will either be handled by your express error handling middleware or thrown.

Joi

Since this middleware is just a wrapper around the Joi validate method all the options are supported.

Running Tests

npm install
npm test

Keywords

FAQs

Package last updated on 06 Aug 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc