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

v0.0.35

Published

node-bits is a node microframework with the aim of providing "just enough" magic to enable you to quickly and painlessly build your api / site.

Downloads

140

Readme

node-bits

node-bits is a node microframework with the aim of providing "just enough" magic to enable you to quickly and painlessly build your api / site. Since every site has different goals, requirements, and tech - node-bits is built as a series a pluggable 'bits' that you can quickly combine into a powerful foundation for your site.

Getting Started

The node-bits package itself is the boot loader. You supply it with the bits and it puts them together. Each bit is intentionally focused on subset of the whole. To cut down on dependency bloat, each bit is distributed as an independent npm package - you only include what you need.

Install

I recommend reading through the list of existing bits, choosing your combination and then installing them together.

For example:

npm install node-bits node-bits-express node-bits-code --save

or

yarn add node-bits node-bits-express node-bits-code

Configuration

Each bit has their own configuration, for example, you may provide a path to the code bit or a connection string to a database bit.

These bits are then provided to the boot loader like:

import nodeBits from 'node-bits';
import nodeBitsExpress from 'node-bits-express';
import nodeBitsCode from 'node-bits-code';
import nodeBitsRest from 'node-bits-rest';

nodeBits([
  nodeBitsExpress({
    port: 4000,
  }),
  nodeBitsCode({
    path: `${__dirname}`,
  }),
  nodeBitsRest({
    prefix: 'api',
  }),
]);

What is a "bit"

A bit is a building block of an app. Below are the existing bits I know about, but you can easily make your own. Each bit is given an opportunity to do something in the following hooks:

  • initialize
  • initializeDatabase
  • loadSchema
  • loadRoutes
  • initializeServer

Current Bits

node-bits-express

The express bit wraps the popular express package for hosting web apps. It will take all routes defined by other bits and configure express to listen for those routes. In addition, it also exposes easy hooks for you to provide custom configurations.

Visit the repo to find out more specifics.

node-bits-code

The code bit allows you to use friendly code to express your schemas and routes. Rather than force you to use a DSL made up by a server or database package, this bit abstracts the concepts of routes and schema to their generic forms, which keeps your code nice, clean and straight forward while reducing complexity and coupling. It also follows the convention of the your folder structure so you can focus on adding value not configuring the server.

Visit the repo to find out more specifics.

node-bits-rest

The rest bit builds and exposes rest services for every schema object defined by bits during loadSchema.

Visit the repo to find out more specifics.

node-bits-mongo

The mongo bit allows you to connect to a mongo database and expose this connection to other bits.

For example, combining this bit with the "code bit" and the "rest bit" will allow you to define your schema in files, and have a fully functional rest setup up with a mongo backend simply by connecting the a couple bits.

Visit the repo to find out more specifics.

node-bits-sql

The sql bit allows you to connect to a sql database and expose this connection to other bits.

For example, combining this bit with the "code bit" and the "rest bit" will allow you to define your schema in files, and have a fully functional rest setup up with a sql backend simply by connecting the a couple bits.

Visit the repo to find out more specifics.

node-bits-password

The password bit provides an implementation of password hashing which can be attached to either mongo or sql database. By simply, defining your field as type PASSWORD, this bit will hash any value saved to that field.

Visit the repo to find out more specifics.

node-bits-spa

The spa bit allows you to quickly configure hosting a single page app at a specified url.

Visit the repo to find out more specifics.

node-bits-jwt

The jwt bit provides an implementation of user based JWT to secure your api and site. It also allows you to restrict access down to the route / verb level by role.

Visit the repo to find out more specifics.

Utility

Log

node-bits exposes three log utility functions. These wrap console.log and use the chalk to color the output appropriately.

log('message', ' part 2');
logWarning('danger will robinson');
logError('error error error');

ExecuteSeries

Promises are common in js, and most times multiple promises can be run 'in parallel' using Promise.all. There are times, often when dealing with a series of db calls, that you need to execute a series of promises in order. node-bits exposes an executeSeries function that accepts an array of promises and executes them in series.

executeSeries([
  db.findById(1),
  Promise.resolve(2),
  db.findById(3),
]);

Timer

The most common first step when profiling an app is to set timers around blocks of code. node-bits exposes three functions to help with this:

startTimer('foo');
toggleTimer('foo');
stopTimer('foo');

Each method defaults to console.log, but accepts a 2nd parameter that can override that. Toggle and Stop will return the time.

Under the covers, node-bits is using performance.now to evaluate the time elapsed.

Constants

There are a few concepts shared across multiple bits such as the following: database types, database relationship types, http verbs, etc. To define them in one place, they live in node-bits.

See the constants.js file for the full list.