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

node-bits-express

v0.0.23

Published

Adds express functionality to NodeBits

Downloads

34

Readme

node-bits-express

node-bits-express wraps the popular web framework express. It iterates through the routes provided by other node-bits packages and exposes them as routes in express. It also exposes a couple of helpers to make setting up your server extremely simple.

Install

npm install node-bits-express --save

or

yarn add node-bits-express

Configuration

node-bits-express accepts an object to detail its configuration. Each property is detailed below.

import nodeBits, { GET,POST,PUT,DELETE,OPTIONS } from 'node-bits';
import nodeBitsExpress, { cors, bodyParser } from 'node-bits-express';

nodeBits([
  nodeBitsExpress({
    port: 3000,
    configurations: [cors({ methods: [GET,POST,PUT,DELETE,OPTIONS] }), bodyParser({limit: '5mb'})],
    hooks: []
  })
];

Port

This is the port the server should listen on. Often this is expressed as the following example to allow runtime configuration:

port: process.env.port || 3000,

Configurations

Configurations are simple functions that setup an attribute of the express server at boot. They are specified as to node-bits-express as items in an array.

configurations: [cors({ methods: [GET,POST,PUT,DELETE,OPTIONS] }), bodyParser],

The signature for these functions is: (app, config) => {}. The first parameter is the express application. The second parameter is the overall config of node-bits.

node-bits-express exposes multiple configurations that we have found used across different projects.

cors

cors uses the cors npm package. It accepts an object that matches the cors config you can find in their documentation. Most often it is simply passing in the methods to which you want cors to apply (as seen in the example above).

bodyParser

body-parser is a middleware for express that will parse the body of a http call and place it at req.body.

It accepts an object that matches the config you can find in their documentation.

  • note: body-parser does NOT handle multipart data. See their documentation for suggestions.

noCache

Depending on what's consuming your api, there are times when get api calls are cached (I'm looking at you IE 11). NoCache adds a middleware to the express response chain to add the following headers:

'Cache-Control': 'no-cache, no-store, must-revalidate'
'Pragma': 'no-cache'
'Expires': 0

Hooks

Hooks allow you to hook into a certain points in the server lifecycle. Right now the two options are BEFORE_CONFIGURE_ROUTES and AFTER_CONFIGURE_ROUTES.

The main use of the hook is the node-bits-jwt bit.