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

init-system

v1.1.2

Published

Declarative startup/shutdown for your Node.js apps.

Downloads

7

Readme

init-system

NPM Version Dependencies Build Status Code Coverage

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

module.exports = {

	// 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.
	*/
	service: function*(services, provide) {

		// Use your dependencies.
		const myService = new MyService(services.config, services.database);

		// Let init-system know the service is ready.
		const exitCode = yield provide(myService);

		// Do our shutdown logic.
		myService.close();

		// Pass on the exit code.
		return exitCode;
	}

};

Then in our main script, load them using init-system.

// index.js

const init = require('init-system');

init.services(

	// Ordering is done in the service descriptions,
	// so we can simply provide an unsorted array.
	[
		require('./services/config.js'),
		require('./services/my-service.js'),
		require('./services/database.js')
	],

	// Node callback.
	function(err, exitCode){
		if(err){
			console.error(`Error during application startup / shutdown: ${err}`);
		} else {
			console.log(`Application exitted with ${exitCode}`);
		}
	}

);

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.

const options = {

	// Sets a logger for verbose startup / shutdown messages.
	logger: function(message) {
		console.log('init-system', message);
	}

};

init.services(
	[/* services */],
	options,
	function(err, exitCode) { /* callback */ }
);