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

ts-async-bootstrap

v2.1.0

Published

ts-async-bootstrap

Downloads

23

Readme

ts-async-bootstrap

Easily setup async typescript applications!

Rationale

When writing node applications, it's a good idea to split up your initialization (database setup, logging setup, etc) from your application entrypoint, that way the initialization can be used for other entry-points (such as admin scripts, scheduled tasks, etc). This package assists bootstrapping the initialization and main function, as well as error handling.

Setup

Install

npm i ts-async-bootstrap

Usage (Option 1)

import { bootstrap } from '../src';

async function setup(): Promise<void> {
	// TODO: Setup some stuff!
}

async function main(): Promise<void> {
	// TODO: Run some stuff!
}

async function errorHandler(e): Promise<void> {
	// TODO: Log some stuff!
}

/**
 * Bootstrap the application
 */
bootstrap({
	register: setup,
	run: main,
	errorHandler: errorHandler
});

Usage (Option 2)

import { Bootstrap } from 'ts-async-bootstrap';

class AppBootstrap extends Bootstrap {
	register = () => {
		// TODO: Setup some stuff!
	}

	onError = (e: Error) => {
		// TODO: Log some stuff!
	}
}

async function main(): Promise<void> {
	// TODO: Run some stuff!
}

export const app = new AppBootstrap();
app.boot(main);

Lifecycle

Register

First, bootstrap() calls your register function, which will setup any dependencies/services/etc before running the main function

Run

Next, your run function is called. This could be the main function of the application, or a admin/scheduled task

Exit

After the run function completes, the onComplete method will be called.

Error

If an exception is thrown or a promise is rejected during register or run, the errorHandler function will be called.

  • If shouldExitOnError is true (default), the application will exit with a non-zero exit code
  • If errorHandler is not set, console.error will be used to log the error
  • If the error occured in the register function, the run function will not be called

Finally

Regardless of success or fail, onFinally will run after onComplete or errorHandler.