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 🙏

© 2025 – Pkg Stats / Ryan Hefner

m10

v0.1.8

Published

Build express APIs in under 10 minutes thanks to centralized development via config file: enter path, input validation and handler function.

Readme

m10

npm version Build Status

Centralized configuration development for Express APIs. Describe your api in one file and just point to handlers and joi validations. All routes with middlewares, handler and validation will be automatically loaded on start-up.

Suitable for:

  • MVPs

  • Prototypes

  • Small APIs

  • Microservices

Scaffold tool: m10-cli

Work in progress

Install

npm install --save m10 or yarn add m10

Supported only Node.js 8+

Usage

const express = require('express')
const app = express()
const m10 = require('m10')
const config = require('./config.json') // m10 configuration

// load m10 config into this app
m10.init(config, app)

app.listen(3000)

Config example

{
  "global": { // apply to all routes
    "middleware": "./middleware/auth.user" // point to file.functionName
  },
  "routes": [ // list of routes
    {
      "path": "/todo/:id",
      "method": "GET",
      "validate": "./schema/todo.findOne" // Joi schema to validate the user input - can be omitted if is not required
      "handler": "./handler/todo.findOne",
      // Optional (one of):
      /*
        Overwrite global middleware for this route only
        you can also use a single path or null

        "middleware": ["./utils/onlyMobileDevice", "./middleware/auth.user"]
      */
      /*
        Append this middleware (after the global one), for this route only
        you can also use an array

        "append_middleware": "./middleware/auth.premiumPlan"
      */
      /*
        Prepend this middleware (before the global one), for this route only
        you can also use an array

        "prepend_middleware": "./middleware/device.mobileOnly"
      */
    },
    {
      "path": "/ping",
      "method": "GET",
      "handler": "./handler/ping.js",
      "middleware": null // overwrite global middleware settings
    },
    {
      "path": "/todo",
      "method": "POST",
      "manager": "./todo.insertOne" // with manager you mean that `todo.insertOne` will have `handler` (todo.insertOne.handler) and `validate` (todo.insertOne.validate) objects
    }
  ]
}

Lifecycle

middleware(s) --> validate --> handler

This flow will stop if one fails/throws (e.g. if validate fails the handler will not be called and the request is returned, same for custom middlewares) - see examples below

File example

global.middleware

Value: ./middleware/auth.user

Will resolve to:

  • File: ./middleware/auth.js

  • Middleware function user

module.exports.user = (req, res, next) => {
  let token = req.headers['x-api-key']
  if (!token || token !== 'password') {
    return res.status(401).send('Token not found/valid') // this will return, validation and handler won't be called 
  }
  // set user id for next routes
  req.session.user_id = 'user_x'
  next()
}

routes[0].validate

Value: ./schema/todo.findOne

Will resolve to:

  • File: ./schema/todo.js

  • Validate object findOne

const { Joi } = require('m10') // import Joi lib
module.exports.findOne = {
  params: { // we want to validate only `params`
    id: Joi.string().max(128).required()
  }
  // here you can also validate `query`, `body` etc..
}

routes[0].handler

Value: ./handler/todo.findOne

Will resolve to:

  • File: ./handler/todo.js

  • Handler function findOne

module.exports.findOne = async (req, res) => {
  // at this point user has passed the global middleware (middleware/auth.user) and has entered a valid :id (schema/todo.findOne)
  let todoFound = await req.db.collections('todo').findOne({todo_id: req.params.id})
  if (todoFound === null) return res.status(404)
  return res.status(200).json(todoFound)
}

routes[2].manager

Value: ./handler/todo.insertOne

Will resolve to:

  • File: ./handler/todo.js

  • Handler function insertOne.handler

  • Validate object insertOne.validate

const { Joi } = require('m10') // import Joi lib
// "manager" will automatically load "validate" and "handler" 
module.exports.insertOne = {
  validate: {
    body: { // this is a POST request, validate body
      title: Joi.string().max(128).required(),
      description: Joi.string().max(2048),
      deadline: Joi.date().required()
    }
  },
  handler: async function (req, res) {
    // at this point user has passed all middlewares and body is validated
    let body = req.body
    let newTodo = Object.assign(body, {
      user_id: req.session.user_id,
      todo_id: 't' + Math.floor(Date.now() / 1000)
    })
    let insertRes = await req.db.collections('todo').insertOne(newTodo)
    res.status(201).json({success: true, todo_id: newTodo.todo_id})
  }
}