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

@nicferrier/crankit

v1.0.8

Published

Make microservice apps easily.

Downloads

14

Readme

A developer tool for microservices?

crank is a tool for developing with the cranker HTTP(S) application router.

Install it like:

$ npm install -g @nicferrier/crankit

and then you can find out about it like:

$ crank help

in addition crank with no arguments will always give you a clue.

What is cranker?

cranker is a sort of service discovery tool.

A service is a small node program (or anything really) providing an HTTP API or UI.

To develop with cranker you want to:

  • start a cranker router
  • start the services that talk to each other or user-agents through cranker
  • tell each service about the cranker endpoint so they can find each other
  • connect each service to the cranker
  • when any service changes then automatically restart it

And you want to do all this without any hassle.

How to develop something with crankit and cranker

If you are developing a blog with 3 services:

  • blog-service
  • user-service
  • blog-frontend

to start a cranker dev environment, you might:

$ cd blog-service
$ crank 8080
$ crank startapp blog server.js
$ crank status
/blog blog-service/server.js running for 10 seconds
$ cd ../user-service
$ crank startapp users server.js
error - what router do you mean? specify a port like

  crank startapp <port> users server.js

$ crank startapp 8080 users server.js
$ crank status
/blog by ../blog-service/server.js on 6652 for 120 seconds
/users by server.js on 6670 for 2 seconds

How does crankit know what router to use?

crank saves a directory called .crankit in the directory in which it was started. This directory records all the information about the router running in the background and when you use a crank command without specifying a router crank tries to find this file to tell it what to do.

If you want to start something outside that directory you need

How does crankit know what port server.js is using

The crank process creates TCP ports for your programs to use and communicates them to your program through an environment variable: APP_PORT.

For example, your program, called server.js:

const express=require("express");
const app = express();
const listener = app.listen(process.env["APP_PORT"]);

can be started like this:

crank startapp blog server.js

crank starts a cranker connector process for server.js with the path blog and a free port that it has allocated and passed to your program on the APP_PORT environment variable.

Using crankit to serve directories

crankit has built in directory serving as a handy extra. Don't feel you have to use it. Making webservers is a trivial process normally and can often have value.

But if you're needing to start webservers, perhaps for 2 or 3 static directories of documentation as you develop then perhaps this is a good way.

It goes like this:

$ crankit 9001                                                   # start on port 9001
$ crankit startdir rustdoc ~/.rustup/toolchain/*/share/doc/html  # serve the rust docs
$ curl http://localhost:9001/rustdoc                             # curl from the cranker

you can startdir as many times as you like, but each one has a separate port internally, they're all internally cranked webservers.

Working with crank with bash completion

To work with crank you might want to load the completion file.

crank can help with that by sending the completion bash source code to the console for you:

If you had checked the repository out and were working without crank installed, you might:

$ source <(node crank complete)

Alternatively, if you have installed it, you could just:

$ source <(crank complete)

the shell script will warn you if crank is not a defined variable name.

A fully automated bash completion system could be achieved by putting this in your .bashrc.

Restarting everything with crankit

If you have a .crankit file you can shut down everything and restart with:

$ crank restart