1.0.0 • Published 9 years ago

bootcheck v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
9 years ago

bootcheck

don't start what you can't finish

Introduction

bootcheck checks that dependencies in package.json are installed and that specified environment variables are defined. bootcheck, itself, has no non-core dependencies so it can be called as soon as a node.js app is started, allowing the app to halt if there are missing dependencies or variables.

The script is intended for use where apps will be run or handled by people who are casual users or who may be in support roles where additional guidance is useful, when first running their app. People working in places with mature environment management tools or DevOps processes are unlikely to find this very useful.

The script was inspired by the Ghost routines that checked for critical dependencies before allowing the app to start.

Installation

bootcheck.js should be copied into an appropriate location within a project's directory structure.

bootcheck is an npm package but it should not be installed with npm.

Why?

You can't check for missing package dependencies if the program checking for dependencies is also missing. It's a chicken and the egg problem...how will you notify there are missing dependencies if the module to check for missing dependencies is, itself, a missing dependency? Yeah?

Also note: bootcheck will not validate or check the values of environment variables to confirm they are good. That responsibility sits with the application code that will consume or manipulate the variable.

Usage

Basic Usage

At the start of the program where bootcheck will help guard against missing dependencies, this would work:

var bc = require("./bootcheck");

bc.pkg("./package.json", "throw");
bc.env(["NODE_ENV", "PORT"], "silent");

action_types for bootcheck

For all methods on the bootcheck object, an action type can be specified that describes how bootcheck should react when there is a problem. These types are:

  1. "throw" - throws an error with a descriptive error message when a requirement is missing
  2. "console" - logs the descriptive error message to the console, but continues operations
  3. "silent" - returns 'false' from the call for other purposes/uses, but does not throw or log

"throw" is the default action and will be used if no action_type is specified when bootcheck methods are called.

Only "throw" will halt execution. "console" and "silent" assume that some other method is in place to assist the app to continue (or that these problems are not fatal, so the app can continue despite the missing requirements).

bootcheck.pkg(package_path, action_type)

package_path should be a path (relative or absolute) to the project's package.json file.

If this path is missing or if package.json has no dependencies, bootcheck will throw an error.

bootcheck.env(variable_array, action_type)

variable_array is a single string or an array of string, each providing the name of an environment variable to confirm are defined.

The .env method will not check the variable values. It simply checks for the presence of the variable in the environment via process.env.<var_name>.

If the variable array is missing, .env will throw an error.

License

ISC