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 🙏

© 2026 – Pkg Stats / Ryan Hefner

initialise

v0.0.2

Published

Lazy initialization / require wrapper. Makes sure you only load the modules once when you need them.

Readme

initialise

Build Status

initialise is a small module that allows you to lazy require/initialise modules when they are accessed. This allows you to easily build light weight core modules that can be shared with various of parts of your infrastructure / services.

Installation

npm install initialise --save

Example

The following example illustrates the power and usage of initialise.

//
// Require the module and hook it on to the exports object
//
var initialise = require('initialise').on(exports);

//
// You can now define lazy loaded modules:
//
initialise('foo', function foo() {
  return require('./foo');
});

We now have a exports.foo method. When you access it, it will load the module foo once and store the result of it. But this is just a simple example of it's use. You can could also use it to require pre-configured database connections, loggers, configuration files and what more. It comes with a small register function that you can use to register a destruction handler. This ensures that every initialised module is cleaned up correctly when initialise.end is called.

var initialise = require('initialise').on(exports);

initialise('config', function () {
  return require('./configuration.json');
});

initialise('redis', function redisClient(register) {
  var config = this.config.get('redis')
    , auth = config.auth || config.password || config.pass
    , redis = require('redis').createClient(config.port, config.host)
    , self = this;

  if (auth) redis.auth(auth);

  redis.on('error', function error(err) {
    console.error(err);
  });

  //
  // Add a clean-up hook. The `redis.quit()` method will wait until all replies
  // have been read instead of forcefully close the connection.
  //
  register('redis', 'quit');

  return redis;
});
initialise.end();

In the example above you also see this.config, this is actually a reference to the exports.config and will lazy load the ./configuration.json file that contains our example redis configuration. It passes the string quit to the register method as that's the method for redis to savely nuke the connection.

If you want to do more advanced clean up operations or need to clean up something that is not method on the returned object you can pass it a function as well:

register('redis', function () {
  // This function will be called when initialise.end() is called.
});

The destruction can also be done async, but initialise is pretty dumb so you have to help it a bit so it understands that this clean up operation is async. So in the case of redis it would simply become:

initialise('redis', function create(register) {
  .. do your redis creation magic, same as example above ..

  register.async('redis', 'quit');

  //
  // As you can see above, we call register.async instead of just register so
  // we can pass in a callback to the method and wait for it to be called.
  //
});

### License

MIT