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-d3ck-bstrap

v0.4.3

Published

Lightweight app bootstrapping

Downloads

35

Readme

npm Version JS-Standard Build Status Dependency Status

node-d3ck-bstrap

Lightweight bootstrapping for node.js applications

Please note the major version of this module: Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable..

Features

Uses the modules node-d3ck-log, node-d3ck-cfg, command-line-args and optional node-uuid to bootstrap (logging, configuration, command line arguments) a node.js application.

Features from node-d3ck-log:

  • Lightweight and simple wrapper + utilities for node-bunyan logger
  • Initializes a preconfigured (STDOUT / info) bunyan logger (sharable across the whole application)
  • Supports bunyan stream and log level changing with utility functions
  • Very lightweight: No extra module dependencies except bunyan
  • Well documented (readme, manual and API reference)

Features from node-d3ck-cfg:

  • Lightweight and simple configuration management based on JSON files
  • Supports staging
  • Supports environment variables and init() arguments to define configuration directories
  • Features a flat configuration structure with camel case keys (nested structures also possible)
  • Very lightweight: No extra module dependencies
  • Well documented (readme, manual and API reference)

Summary of command-line-args:

  • A library to collect command-line args and generate a usage guide

Summary of node-uuid:

  • Simple, fast generation of RFC4122 UUIDS

Installation

npm install node-d3ck-bstrap

Usage

Configuration file:

$ cat /home/foo/etc/cfg.json
{"foo": "from cfg file"}

node.js application:

var bstrap = require('node-d3ck-bstrap')
var cfg = bstrap.cfg
var log = bstrap.log

// define supported command line arguments
var clargs = {
  args: [
    {name: 'action', alias: 'a', type: String, description: 'Action: start, stop'}
  ],
  addArgs: ['help', 'verbose', 'quiet', 'stage', 'cfgdir'],
  usage: {
    title: 'Sample script for node-d3ck-bstrap',
    description: 'An application bootstrapped by node-d3ck-bstrap',
    synopsis: [
      '$ node [bold]{foo.js} --action X [--verbose] [--stage X] ...',
    ],
    examples: [
      '$ node [bold]{test.js} --action start --verbose'
    ],
    footer: 'Project home: [underline]{https://github.com/d3ck-org/node-d3ck-bstrap}'
  }
}

// bootstrapping
var opts = {stage: 'dev', uuid: false}
var data = {bar: 'from init()'}
bstrap.init(clargs, opts, data)

// print the configuration with the STDOUT-info bunyan logger
log.info({cfg: cfg.get()}, 'Dumping configuration')

Run the application:

$ node /path/to/script/foo.js -a start | ./node_modules/node-d3ck-log/node_modules/.bin/bunyan
  [2015-11-09T15:34:09.330Z]  INFO: stdout/2901: Dumping configuration
    cfg: {
      "_startTime": 1447083402646,
      "_myFilePath": "/path/to/script/foo.js",
      "_clargs": {                        // all command line arguments
        "action": "start"
      },
      "_pid": 2924,
      "_errors": 0,
      "_warnings": 0,
      "_count": 0,
      "_logLevel": "info",
      "_logStream": "stdout",
      "_verbose": false,
      "_quiet": false,
      "_uuid": null,
      "_uid": "path_to_script_foo_js",
      "_myFileName": "foo.js",
      "_myDirPath": "/path/to/script",
      "_tmpFileName": "foo.js.tmp",
      "_stage": "dev",
      "_cfgFiles": [
        "/path/to/script/cfg.json"
      ],
      "action": "start",                  // command line argument
      "bar": "from init()",               // init() argument
      "foo": "from cfg file"              // JSON cfg file value
    }

So, node-d3ck-bstrap ...

  • reads the JSON configuration file
  • parses the command line arguments
  • exports the configuration, command line arguments and some other useful values as cfg
  • initializes and preconfigures the bunyan logger

When the --help command line argument is set, only the usage message is printed:

$ node /path/to/script/foo.js -h
  USAGE HELP:

  Sample script for node-d3ck-bstrap
    An application bootstrapped by node-d3ck-bstrap

  Synopsis
    $ node foo.js --action X [--verbose] [--stage X] ...

  Options
    -a, --action string   Action: start, stop                   
    -h, --help            Display this usage guide              
    -v, --verbose         Enable verbose mode                   
    -Q, --quiet           Enable silent mode                    
    -S, --stage string    Set stage (e.g. to dev, test or prod)

  Examples
    $ node foo.js --action start --verbose

    Project home: https://github.com/d3ck-org/node-d3ck-bstrap

Documentation

See also / Credits