Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Wrap modules so they can be reloaded via external signal or in process. Useful for config modules.
JavaScript
tag: v0.0.3

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.travis.yml
README.md
index.js
package.json
settings1.js
settings2.js
test.js

README.md

reloadable Build Status

This is a simple wrapper around a module that allows it to be reloaded on signals, which is particularly useful when using a module for configuration.

Synopsis

// config.js
module.exports = {
  someService: {
    username: 'stephen'
    password: 'blahblah'
  }
}

// app.js
var config = require('reloadable')(__dirname + '/config', {
  signal: 'SIGHUP',
  // This is the default error handler, override it if you need more.
  exposeReload: true
  error: function(err, path) {
    console.error(path, err)
  }
})

var client = require('./service-client')(config)
config.reload()

Install

npm install reloadable

API

require('reloadable') returns a function that takes a module path and an options object. The path will be passed to require unmodified inside the reloadable module, so it should not be relative.

The options object can be omitted, or contain any of the following keys:

  • signal - If given, the configuration reload function will be called when the process recieves the given signal.
  • *exposeReload - If true, the reload function will be assigned to .reload on the returned object. Caution, this will hide any existing property named 'reload' your object might have.
  • error - A function that will be called with (err, path) if an exception is thrown while reloading the module. The default prints the path and error to stderr.

License

MIT

Something went wrong with that request. Please try again.