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

boot-in-the-arse

v0.3.0

Published

Asynchronous bootstrapping of Node applications

Downloads

54

Readme

boot-in-the-arse   Build Status

Asynchronous bootstrapping made easy. Wait for all components/plugins to start, and then start your whole app.

boot-in-the-arse is fully reentrant and graph-based. You can load components/plugins within plugins, and be still sure that things will happen in the right order.

JavaScript Style Guide

Install

To install boot-in-the-arse, simply use npm:

npm install boot-in-the-arse --save

Example

The example below can be found here and ran using node example.js. It demonstrates how to use boot-in-the-arse to load functions / plugins in order.

'use strict'

const boot = require('boot-in-the-arse')()

boot
  .use(first, { hello: 'world' })
  .after((cb) => {
    console.log('after first and second')
    cb()
  })
  .use(third, (err) => {
    if (err) {
      console.log('something bad happened')
      console.log(err)
    }

    console.log('third plugin loaded')
  })
  .ready(function () {
    console.log('application booted!')
  })

function first (instance, opts, cb) {
  console.log('first loaded', opts)
  instance.use(second, cb)
}

function second (instance, opts, cb) {
  console.log('second loaded')
  process.nextTick(cb)
}

function third (instance, opts, cb) {
  console.log('third loaded')
  cb()
}

API

  • boot()
  • instance.use()
  • instance.after()
  • instance.ready()
  • boot.express()

boot([instance], [started])

Start a booting sequence.

instance will be used as the first argument of all plugins loaded and use, after and ready  function will be added to that object, keeping the support for the chainable API:

const server = {}

require('boot-in-the-arse')(server)

server.use(function first (s, opts, cb) {
  // s is the same of server
  s.use(function second (s, opts, cb) {
    cb()
  }, cb)
}).after(function (cb) {
  // after first and second are finished
  cb()
})

Options:

  • expose: a key/value property to change how use, after and ready are exposed.

Events:

  • 'error'  if something bad happens
  • 'start'  when the application starts

The boot function can be used also as a constructor to inherits from.


app.use(func, [opts], [cb])

Loads a functions asynchronously. The function must have the signature:

function plugin (server, opts, done) {
  done()
}

done must be called only once.

Returns the instance on which use is called, to support a chainable API.

If you need to add more than a function and you don't need to use a different options object or callback, you can pass an array of functions to .use.

boot.use([first, second, third], opts, cb)

The functions will be loaded in the same order as they are inside the array.


app.after(func([done]), [cb])

Calls a functon after all the previously defined plugins are loaded, including all their dependencies. The 'start' event is not emitted yet.

boot.after(function (done) {
  done()
})

done must be called only once.

Returns the instance on which after is called, to support a chainable API.


app.ready(func([done]))

Calls a functon after all the plugins and after call are completed, but befer 'start' is emitted. ready callbacks are executed one at a time.

boot.ready(function (done) {
  done()
})

done must be called only once.

Returns the instance on which ready is called, to support a chainable API.


boot.express(app)

Same as:

const app = express()

boot(app, {
  expose: {
    use: 'load'
  }
})

Acknowledgements

This project was kindly sponsored by nearForm.

License

Copyright Matteo Collina 2016, Licensed under MIT.