npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-suite

v1.6.3

Published

A collection of useful express middlewares

Downloads

43

Readme

express-suite

A collection of Middlewares for Express

Maintainability Codacy Badge npm version

:) More middlewares will be available as the time progresses.

Installation

$ npm i express-suite

routeCheck

This middleware will handle all requests to non-registered routes for you.

In the config option, you can specify a route to handle all requests to non-existing routes. For example, a custom page-not-found notice.

If no config option is passed, the middleware will send a 404 to those requests.

//Dependencies
const express = require('express');

//Require the routeCheck Middleware
const { routeCheck } = require('express-suite');

//Initialize the App
const app = express();

//Load Routes
const example = require('./routes/example');

//Use Routes
app.use('/', example);

//The routeCheck middleware config option
//The redirectPath refers to the custom route you want to redirect the requests to
const options = { redirectPath: '/PnF' };

//It's important to use the routeCheck middleware after all routes are loaded
app.use(routeCheck(app, options));

//Start the server
app.listen(5003);

emptyInputCheck

This middleware checks for all empty inputs to all routes (unless used at a router level) by checking the body of both POST and GET requests.

Note: 0 does count as a valid input.

Default Error Messages:

  1. Requests with an empty body will be met with a 400 and the message:
{
  msg: 'The request body is empty!';
}
  1. Request with empty fields in the body will be met with a 400 and the message:
{
  msg: 'The request body is empty!',
  field:'key of the missing field'
}
//supressFieldKey=true
{
  msg: 'The request body is empty!',
}

You can specify the middleware to skip the check for GET requests in the config option.

Custom error message for each scenario above and whether to supress the filed key can be specified like the example below:

//Dependencies
const express = require('express');
const bodyParser = require('body-parser');

//Require the routeCheck Middleware
const { emptyInputCheck } = require('express-suite');

//Initialize the App
const app = express();

//bodyParser Middleware
app.use(
  bodyParser.json({
    limit: '5mb',
    extended: true,
  }),
);

//The emptyInputCheck Middleware
//It's important that we place the emptyInputCheck Middleware after the bodyParser middleware
//Make sure you call the emptyInputCheck middleware before the routes are loaded
app.use(
  emptyInputCheck({
    checkGet: true, //Wether to check the GET requests or not
    emptyBodyMsg: 'Err Msg 1', //Custom msg for empty body
    emptyFieldMsg: 'Err Msg 2', //Custom msg for missing fields
    supressFieldKey: false, //To supress the key of the missing field
  }),
);

//Load Routes
const example = require('./routes/example');

//Use Routes
app.use('/', example);

//Start the server
app.listen(5003);

Tests

The poject uses Jest for testing.

Clone the Github repo. first. Install the dependencies then run npm test

$ git clone https://github.com/algo7/express-suite.git
$ cd express-suite
$ npm i
$ npm test

Depedency Graph

DepGraph

Generated using dependency-cruiser

Known Issues

express-suite's emptyInputCheck function does not work well with Multer

License

Apache License 2.0