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

@fendy3002/express-helper

v0.4.1

Published

With NPM:

Downloads

27

Readme

A set of utility tools for express server

Installation

With NPM:

$ npm install --save @fendy3002/express-helper

Or using yarn :

$ yarn add @fendy3002/express-helper

Healthcheck

  • Add Health Endpoint

GET /~/health

Only checks whether the application server is running. It does not verify whether database or other services are running. A successful response will return a 204 status code without content

  • Add Readiness Endpoint

GET /~/readiness

Check whether database or other services are running. Usually used at startup to check whether required services are already up, for example is database. Or whether something happen to services when the server produce an error.

import {healthCheck} from '@fendy3002/express-helper';

app.use(healthCheck{
    mongo: async (req, res) => {
        await mongoose.connection.db.admin().ping();
        return;
    },
    // default 10000 or 10 secs
    checkTimeout: 10000
})

Filter Parser

This module / library will parse key-value query / body based on prefix, compare with supplied schema, and returning mongodb or mongoose filter (and possibly sequelize in the future).

Usage:

import {filterParser} from '@fendy3002/express-helper';

app.get('/', async (req, res, next) => {
    let filter = await mongoFilter(req.query, {
      "age": {
        "key": "userAge",
        "type": "number"
      }
    }, {
        prefix: "filter"
      });
    let listData = mongoModel.find(filter);
});

This will parse any query / body start with filter., for example filter.age or filter.name. Read more on Content section.

Parameters:

  • content: key-value object. Not strictly enforced but recommend if the value is string. Usually req.query or req.body. Read more on Content section.
  • schema: key-value object. The schema to define data types and filter keys. Read more on Schema section
  • option.prefix: string. The prefix which part of query / body to parse (without suffix dot). The default prefix is filter
  • option.validateKey: boolean, default false. If true, it will check the schema to compare. If the content key does not exists in schema, it'll throw error
  • option.notFoundKeyError: boolean, default true. If true, it will throw error if validateKey option is true, and the content key does not exists in schema. Otherwise it just skip the property

Content

Is a key-value object, and only properties with matching prefix (defined in option) are being used. For example if the prefix is filter, from the following req.query (or req.body) data:

{
    "name": "Luke Skywalker",
    "age": "15",
    "filter.category": "REGULAR",
    "filter.transactionDate": "2001-01-01"
}

Only 2, filter.category and filter.transactionDate that will be used as filter. There are several operations that can be used to help for conditional filter, for example in the following content:

{
    "filter.transactionDate.from": "2001-01-01",
    "filter.transactionDate.to": "2001-01-03"
}

Will result in filter logic of transactionDate >= 2001-01-01 AND transactionDate <= 2001-01-03. The available operations are:

  • eq: equals. If not defined the operation will default to eq
  • ne: not equals
  • from or gte: greater than or equals
  • gt: greater than
  • to or lte: less than or equals
  • lt: less than
  • regex: regex comparison
  • contains: search for records with field which contains value, similar with sql's like '%' + value + '%'
  • starts_with: search for records with field which starts with value, similar with sql's like '%' + value
  • ends_with: search for records with field which ends with value, similar with sql's like value + '%'

Schema

Key-value object containing the schema / data type definition. The value can be either string or object. Each content properties with matched prefix will be searched for schema. If found, it'll use the schema definition. If not found, the data type will set to string. If not found and option.validateKey is set to true, it'll throw error if option.notFoundKeyError is true. Otherwise the property will be skipped.

Example string schema:

{
    "name": "name",
    "trxDate": "transactionDate"
}

This will keep filter.name property as name, but will change filter.trxDate to transactionDate. Useful if you want to have different query and schema property name.

{
    "price": {
        "key": "totalPrice",
        "type": "number"
    },
    "trxDate": {
        "key": "transactionDate",
        "type": "date",
        "formatFrom": "YYYY-MM-DD",
        "formatTo": "YYYY-MM-DD HH:mm:ss",
        "endOfDay": false
    },
    "timestampDate": {
        "key": "transactionTimestamp",
        "type": "timestamp",
        "formatFrom": "YYYY-MM-DD",
        "endOfDay": false
    }
}