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

chillin

v1.0.4

Published

NPM package API and Bash/CLI tool to implement waiting on an external resource's availability.

Downloads

11

Readme

Introduction

This tool is intended to be used either in bash or a node.js project. It waits for a resource (such as a database) to become available, then it starts another process. It just chills until the timeout expires or the wait condition is satisfied.

Let's illustrate with an example. Say you have a Docker Compose environment that starts containers S and D (for database). S depends on D, but D can be slow to start up. S can use chillin in either of two ways.

  1. The NodeJS startup script can be modified to use the chillin NPM package.
  2. A startup bash script can utilize the chillin CLI.

Please Note Chillin uses EcmaScript 6. It will not run on older versions of NodeJS!

NodeJS Example

const chillin = require('chillin')
    , promise = chillin.loadWaiterModule('port')
        .configure('host', 'www.google.com')
        .configure('port', 80)
        .start()

promise.then(function(){
    console.log('OK!')
}, function(x){
    console.error(`Failed: ${x}`)
})

To Run Chillin Inside Your Project

> npm install chillin --save-dev
> export PATH=$PATH:$(npm bin)
> chillin port www.google.com 80

BASH Example

Please reference the example above if you are installing Chillin in your project rather than as a global package. The line that changes the PATH variable can be added to the example below to make it run with a locally installed package.

#!/usr/bin/env bash

if [ $# -lt 1 ]; then
    echo "Name/IP of Postgres server required." 1>&2;
    echo "> $0 PGSERVER" 1>&2;
    exit 1
fi

#If you want to suppress error output on failure, you can redirect
#stderr to null on the next line.
chillin port $1 5432
#Get the exit code
RESULT=$?

if [ $RESULT == 0 ]; then
    echo "Starting the program that depends on Postgres..."
else
    echo "Failed! Not starting the program." 1>&2
    exit $RESULT
fi

Types of Waits

There are three built-in waiter modules: port, exec, and mock. The port waiter is shown in the examples. The exec module waits for a process to start and complete or time out. The mock module is for testing purposes. Other modules may be loaded using a path consistent with require() in NodeJS.

The port Waiter

chillin www.github.com 80 --timeout 2000

The positional arguments are ADDRESS PORT

The exec Waiter

chillin --timeout 2000 echo "Hello"

The positional arguments correspond to COMMAND arg1 arg2 ... argN