init-system
Declarative startup/shutdown for your Node.js apps.
This solution has a dependency declarations similar to Linux startup systems or Makefiles. It also has inversion of control similar to middleware.
Project status
Unmaintained
This module saw sucessful deployments into production for projects I worked on, but we eventually decided to move to booture. The functionality and syntax are similar, but it offers cleaner integration into Fluture and well defined behaviour since it's based on Fluture Hooks.
Usage
First we need to declare our services.
// services/my-service.js moduleexports = // The name of this service. provides: 'myService' // The dependencies of this service. after: 'config' 'database' /* Below is the startup and shutdown logic. services: object This object holds all of the dependencies declared in "after". provide: function(value) => Future A function you need to call to signal your service is created and ready for use. */ { // Use your dependencies. const myService = servicesconfig servicesdatabase; // Let init-system know the service is ready. const exitCode = ; // Do our shutdown logic. myService; // Pass on the exit code. return exitCode; } ;
Then in our main script, load them using init-system
.
// index.js const init = ; init;
Available options
You can call init.services(services, [options], callback)
with an options object to change some behavior.
key | type | description |
---|---|---|
logger | function(message) |
Allows you to set a logger for verbose startup / shutdown messages. |
View example usage for the options
const options = // Sets a logger for verbose startup / shutdown messages. { console; } ; init;