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

@strv/heimdall

v2.2.0

Published

A simple process signal manager

Downloads

2,084

Readme

@strv/heimdall

Build Status

The process lifecycle gatekeeper.

Built with ❤️ at STRV

Heimdall takes control over the Node.js process' signal handling and provides a simple way to respond to various process lifecycle events.

Installation

npm i --save @strv/heimdall

Usage

import { heimdall } from '@strv/heimdall'
// Import something important. Maybe a Koa server? Or Atlas.js instance?
import { app } from './app'

heimdall({
  /**
   * The execute method is invoked by Heimdall immediately after calling `heimdall()`. You can
   * start your servers and set up any other important tasks here.
   * @return    {Promise}
   */
  async execute() {
    // Start whatever you need to start in this process. Whatever you return from this function, you
    // will receive it in the .exit() method below.
    return await app.start(process.env.PORT)
  },

  /**
   * This method will be invoked by Heimdall when the process receives a `SIGINT` or `SIGTERM`
   * signal. This method is also invoked when Node.js' event loop will empty and Node determines
   * that it can safely exit itself.
   * @return    {Promise}
   */
  async exit({ runtime }) {
    // Stop your servers, close down your open sockets or other activities that might be
    // keeping the Node process running.
    await app.stop()

    // runtime is exactly what you returned in .execute(), in this case it is the Koa instance
    app === runtime
  },

  /**
   * This optional method will be invoked by Heimdall when the process receives a second `SIGINT` or
   * `SIGTERM` signal (ie. the user pressing ctrl+c twice). You can log something to the console or
   * perform synchronous cleanup, but the Node process will be terminated shortly and any async I/O
   * operations are not guaranteed to complete in time.
   * @return    {void}
   */
  didReceiveForcequit() {
    // This is a synchronous method call. Running async I/O operations is not guaranteed to work.
  },

  /**
   * This optional method will be used by Heimdall when one of the Delegate's methods throws an
   * error. Heimdall logs these errors to the stderr output stream but if you implement this method,
   * it will let you log the error using your logging solution of choice.
   *
   * The log should be synchronous as the process will be terminated in the next event loop.
   */
  logError(err) {
    pino.error({ err }, 'heimdall received error')
  }

  /**
   * Set this to true to let Heimdall call the exit handler as soon as the execute handler finishes
   *
   * This is ideal for one-off scripts, commands or other utilities where you want to do a task and
   * then let the process exit gracefully.
   */
  exitAfterExecute?: false
})

License

See the LICENSE file for information.