node package manager



NPM version NPM monthly downloads Build Status Gitter

Table of contents About

Why use Base?

Base is the foundation for creating modular, unit testable and highly pluggable node.js applications.

  • Go from zero to working application within minutes
  • Create your own custom plugins to add features
  • Use community plugins to add feature-functionality to your application
  • Plugins are stackable, so you can build up more sophisticated applications from simpler plugins. Moreover, those applications can also be used as plugins themselves.

Most importantly, once you learn Base, you will be familiar with the core API of all applications built on Base. This means you will not only benefit as a developer, but as a user as well.

Guiding principles

The core team follows these principles to help guide API decisions:

  • Compact API surface: The smaller the API surface, the easier the library will be to learn and use.
  • Easy to extend: Implementors can use any npm package, and write plugins in pure JavaScript. If you're building complex apps, Base dramatically simplifies inheritance.
  • Easy to test: No special setup should be required to unit test Base or base plugins

Minimal API surface

The API was designed to provide only the minimum necessary functionality for creating a useful application, with or without plugins.

Base core

Base itself ships with only a handful of useful methods, such as:

  • .set: for setting values on the instance
  • .get: for getting values from the instance
  • .has: to check if a property exists on the instance
  • .define: for setting non-enumerable values on the instance
  • .use: for adding plugins

Be generic

When deciding on method to add or remove, we try to answer these questions:

  1. Will all or most Base applications need this method?
  2. Will this method encourage practices or enforce conventions that are beneficial to implementors?
  3. Can or should this be done in a plugin instead?


Plugin system

It couldn't be easier to extend Base with any features or custom functionality you can think of.

Base plugins are just functions that take an instance of Base:

var base = new Base();
function plugin(base) {
  // do plugin stuff, in pure JavaScript 
// use the plugin 

Add "smart plugin" functionality with the base-plugins plugin.


Easily inherit Base using .extend:

var Base = require('base');
function MyApp() {;
var app = new MyApp();
app.set('a', 'b');
//=> 'b'; 

Inherit or instantiate with a namespace

By default, the .get, .set and .has methods set and get values from the root of the base instance. You can customize this using the .namespace method exposed on the exported function. For example:

var Base = require('base');
// get and set values on the `base.cache` object 
var base = Base.namespace('cache');
var app = base();
app.set('foo', 'bar');
//=> 'bar' 




Install with npm:

$ npm install --save base


Install with yarn:

$ yarn add base && yarn upgrade


var Base = require('base');
var app = new Base();
// set a value 
app.set('foo', 'bar');
//=> 'bar' 
// register a plugin 
app.use(function() {
  // do stuff (see API docs for ".use") 



Create an instance of Base with the given config and options.


  • config {Object}: If supplied, this object is passed to cache-base to merge onto the the instance upon instantiation.
  • options {Object}: If supplied, this object is used to initialize the base.options object.


// initialize with `config` and `options` 
var app = new Base({isApp: true}, {abc: true});
app.set('foo', 'bar');
// values defined with the given `config` object will be on the root of the instance 
console.log(app.baz); //=> undefined 
console.log(; //=> 'bar' 
// or use `.get` 
console.log(app.get('isApp')); //=> true 
console.log(app.get('foo')); //=> 'bar' 
// values defined with the given `options` object will be on `app.options 
console.log(; //=> true 


Set the given name on app._name and* properties. Used for doing lookups in plugins.


  • name {String}
  • returns {Boolean}

//=> 'foo' 
//=> true'bar');
//=> true 
//=> true 
//=> 'bar' 


Returns true if a plugin has already been registered on an instance.

Plugin implementors are encouraged to use this first thing in a plugin to prevent the plugin from being called more than once on the same instance.


  • name {String}: The plugin name.
  • register {Boolean}: If the plugin if not already registered, to record it as being registered pass true as the second argument.
  • returns {Boolean}: Returns true if a plugin is already registered.


  • emits: plugin Emits the name of the plugin being registered. Useful for unit tests, to ensure plugins are only registered once.


var base = new Base();
base.use(function(app) {
  if (app.isRegistered('myPlugin')) return;
  // do stuff to `app` 
// to also record the plugin as being registered 
base.use(function(app) {
  if (app.isRegistered('myPlugin', true)) return;
  // do stuff to `app` 


Define a plugin function to be called immediately upon init. Plugins are chainable and expose the following arguments to the plugin function:


  • fn {Function}: plugin function to call
  • returns {Object}: Returns the item instance for chaining.


var app = new Base()


The .define method is used for adding non-enumerable property on the instance. Dot-notation is not supported with define.


  • key {String}: The name of the property to define.
  • value {any}
  • returns {Object}: Returns the instance for chaining.


// arbitrary `render` function using lodash `template` 
app.define('render', function(str, locals) {
  return _.template(str)(locals);


Mix property key onto the Base prototype. If base is inherited using Base.extend this method will be overridden by a new mixin method that will only add properties to the prototype of the inheriting application.


  • key {String}
  • val {Object|Array}
  • returns {Object}: Returns the base instance for chaining.


app.mixin('foo', function() {
  // do stuff 


Getter/setter used when creating nested instances of Base, for storing a reference to the first ancestor instance. This works by setting an instance of Base on the parent property of a "child" instance. The base property defaults to the current instance if no parent property is defined.


// create an instance of `Base`, this is our first ("base") instance 
var first = new Base(); = 'bar'; // arbitrary property, to make it easier to see what's happening later 
// create another instance 
var second = new Base();
// create a reference to the first instance (`first`) 
second.parent = first;
// create another instance 
var third = new Base();
// create a reference to the previous instance (`second`) 
// repeat this pattern every time a "child" instance is created 
third.parent = second;
// we can always access the first instance using the `base` property 
//=> 'bar' 
//=> 'bar' 
//=> 'bar' 
// and now you know how to get to third base ;) 


Static method for adding global plugin functions that will be added to an instance when created.


  • fn {Function}: Plugin function to use on each instance.
  • returns {Object}: Returns the Base constructor for chaining


Base.use(function(app) { = 'bar';
var app = new Base();
//=> 'bar' 


Static method for inheriting the prototype and static methods of the Base class. This method greatly simplifies the process of creating inheritance-based applications. See static-extend for more details.


  • Ctor {Function}: constructor to extend
  • methods {Object}: Optional prototype properties to mix in.
  • returns {Object}: Returns the Base constructor for chaining


var extend = cu.extend(Parent);
// optional methods 
Parent.extend(Child, {
  foo: function() {},
  bar: function() {}


Used for adding methods to the Base prototype, and/or to the prototype of child instances. When a mixin function returns a function, the returned function is pushed onto the .mixins array, making it available to be used on inheriting classes whenever Base.mixins() is called (e.g. Base.mixins(Child)).


  • fn {Function}: Function to call
  • returns {Object}: Returns the Base constructor for chaining


Base.mixin(function(proto) { = function(msg) {
    return 'foo ' + msg;


Static method for running global mixin functions against a child constructor. Mixins must be registered before calling this method.


  • Child {Function}: Constructor function of a child class
  • returns {Object}: Returns the Base constructor for chaining




Similar to util.inherits, but copies all static properties, prototype properties, and getters/setters from Provider to Receiver. See class-utils for more details.


  • Receiver {Function}: Receiving (child) constructor
  • Provider {Function}: Providing (parent) constructor
  • returns {Object}: Returns the Base constructor for chaining


Base.inherit(Foo, Bar);

Toolkit suite

Base is used as the foundation for all of the applications in the toolkit suite (except for enquirer):

Building blocks

  • base: (you are here!) framework for rapidly creating high quality node.js applications, using plugins like building blocks.
  • templates: API for managing template collections and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator, blog framework, documentaton system, and so on.
  • enquirer: composable, plugin-based prompt system (Base is used in prompt-base, the core prompt module that powers all prompt plugins)


Developer frameworks and command line tools that address common phases of the software development lifecycle. Each of these tools can be used entirely standalone, but they work even better together.


Related projects


Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test


Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

If Base doesn't do what you need, please let us know.

Release History


Changelog entries are classified using the following labels from keep-a-changelog:

  • added: for new features
  • changed: for changes in existing functionality
  • deprecated: for once-stable features removed in upcoming releases
  • removed: for deprecated features removed in this release
  • fixed: for any bug fixes

Custom labels used in this changelog:

  • dependencies: bumps dependencies
  • housekeeping: code re-organization, minor edits, or other changes that don't fit in one of the other categories.

Heads up!

Please let us know if any of the following heading links are broken. Thanks!



  • ensure __callbacks and super_ are non-enumberable


  • Now sets app.type when'foo') is called. This allows Base instances to be used more like AST nodes, which is especially helpful with smart plugins


Major breaking changes!

  • Static .use and .run methods are now non-enumerable


Major breaking changes!

  • .is no longer takes a function, a string must be passed
  • all remaining .debug code has been removed
  • app._namespace was removed (related to debug)
  • .plugin, .use, and .define no longer emit events
  • .assertPlugin was removed
  • .lazy was removed

(Changelog generated by helper-changelog)


Jon Schlinkert

Brian Woodward


Copyright © 2017, Jon Schlinkert. MIT

This file was generated by verb-generate-readme, v0.4.3, on April 02, 2017.