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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sanar-ms

v1.1.0

Published

![sanar-ms-cover-v3](https://user-images.githubusercontent.com/6170412/61061735-312d7380-a3d3-11e9-85b6-f299e5ce12cb.png)

Readme

sanar-ms-cover-v3

sanar-ms

Framework to create Sanar Microservices. With this library you are able to quickly create a extensible microservice following the standards adopted by Sanar.

Features:

  • [X] Setup Express Server: Quickly setup all API server
  • [X] Logger: Pretty logging with multiple transports
  • [X] Env Vars: Assert and Validate environment variables
  • [X] Healthcheck: Customize how we know the service is health
  • [X] Database Integration: Create and assert database connection
  • [X] API Validator: Validating request body/queries/cookies/headers
  • [X] API Pagination: Standardization of pagination in API

Basic Usage


import * as SanarMS from 'sanar-ms';

const ms = new SanarMS({
  name: 'questions',
});

ms.app.get('/hello', (req, res) => {
  res.json({ hello: 'world' });
});

ms.listen();

Documentation

Full options example

const opts = {
  name: 'my-service',
  middlewares: {
    push: [],
    unshift: [],
    overwrite: [],
  },
  logger: {
    transports: [
      new winston.transports.Console(),
    ],
    silent: false,
    level: 'info',
  },
  envs: [
    {
      name: 'MONGO_HOST',
      type: 'url',
      required: true,
    },
    {
      name: 'MONGO_PORT',
      type: 'port',
    },
  ],
  validator: ({ body, query }) => ({
    createUser: [
      body('name')
        .isString()
      query('enabled')
        .isBoolean()
    ],
  }),
}

Options

Basic Setup

  • name (String): Microservice name

Server Setup

  • middlewares.unshift (Array): Unshift/Prepend Express middleware before all default middlewares.
  • middlewares.push (Array): Push/Append Express middleware after all default middlewares.
  • middlewares.overwrite (Array): Overwrite all default Express. Note: when defined, unshift and push will be ignored.

Logger

  • logger.transports (Array): List of Logger transports (See more: winston-transports)
  • logger.level (String): Log only if logger.level less than or equal to this level
  • logger.silent (Boolean): If true, all logs are suppressed

Environment Variables

  • envs (Array[env]): List of environment variable definitions

Environment Object Properties

  • env.name (String): Env variable name. Ex: MONGO_HOST
  • env.type (String): Env variable type. Ex: int. See below all types.
  • env.required (String): If true and not defined, the Microservie crashes.

Environment Variable Types

  • int: Parse int number. Example: 123
  • float: Parse float number. Example 12.8
  • string Parse string. Example 'Hello'
  • boolean. Parse boolean. Example: true
  • host. Parse host. Example: localhost
  • port. Parse port. Example: 3000
  • url. Parse url. Example: http://editorasanar.com.br

Healthcheck

  • health (Function): Custom function to assert the Microservice is healthy. Returns true healthy / false unhealthy

Database

  • database.enabled: Enable / Disable database
  • database.type: Database type. See the list of Database types below.

Database Types

  • mongo: MongoDB using Mongoose framework

Note: Currently we are only giving support to mongo database.

Validator

  • database.validator: Function that should return a map of key => validationMiddlewares

Note: We use express-validator. See all validator types.


Examples

Example 1 - Extending middlewares with Unshift / Push:

const beforeMiddleware = (req: any, res: any, next: any) => {
  console.log('Before all default middlewares');
  next();
};

const afterAllMiddleware = (req: any, res: any, next: any) => {
  console.log('After all default middlewares');
  next();
};

const ms = new SanarMS({
  name: 'my-service',
  middlewares: {
    unshift: [
      beforeMiddleware,
    ],
    push: [
      afterAllMiddleware,
    ]
  }
});

Example 2 - Overwriting middlewares:

const ms = new SanarMS({
  name: 'my-service',
  middlewares: {
    overwrite: [
      bodyParser.json(),
    ],
  }
});

Example 3 - Custom Logger Transports:

const ms = new SanarMS({
  name: 'my-service',
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'app.log' }),
    new AwsCloudWatch(options),
  ],
});