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

core_d

v6.1.0

Published

Offload your heavy lifting to a daemon

Downloads

166,295

Readme

core_d

Build Status SemVer License

Offload your heavy lifting to a daemon. Extracted from eslint_d.

Install

This will install the core_d as a dependency:

❯ npm install core_d

Usage

You need to create a main file that controls the daemon and a service.js file which will run in the background.

The main file should look something like this:

const cmd = process.argv[2];

process.env.CORE_D_TITLE = 'your_d';
process.env.CORE_D_DOTFILE = '.your_d';
process.env.CORE_D_SERVICE = require.resolve('./your-service');
// optional to get logging from the child process
process.env.CORE_D_DEBUG = 'true';

const core_d = require('core_d');

if (cmd === 'start'
  || cmd === 'stop'
  || cmd === 'restart'
  || cmd === 'status') {
  core_d[cmd]();
  return;
}

core_d.invoke(process.argv.slice(2));

The service.js file must expose an invoke function like this:

/*
 * The core_d service entry point.
 */
exports.invoke = function (cwd, args, text, callback) {
  callback(null, 'Your response');
};

How does this work?

The first time you call core_d.invoke(...), a little server is started in the background and bound to a random port. The port number is stored along with a security token in the configured dotfile. Your services invoke method is called with the same arguments. Later calls to invoke will be executed on the same instance. So if you have a large app that takes a long time to load, but otherwise responds quickly, and you're using it frequently, like linting a file, then core_d can give your tool a performance boost.

API

The core_d client exposes these functions:

  • start(): Starts the background server and create the dotfile. It's not necessary to call this since invoke will start the server if it's not already running.
  • stop(): Stops the background server and removed the dotfile.
  • restart(): Stops and starts the background server again.
  • status(): Prints a status message saying whether the server is running or not. If the server is running and your service implements getStatus(), the return value will be printed as well.
  • invoke(args[, text]): Invokes the invoke methods in the service.

Environment variables:

  • CORE_D_TITLE: The process title to use. Optional.
  • CORE_D_DOTFILE: The name of dotfile to use, e.g. .core_d.
  • CORE_D_SERVICE: The resolved path to the service implementation. Use require.resolve('./relative-path') to receive the resolved path.

Your service must implement a function with the signature invoke(cwd, args, text, callback). The passed arguments are:

  • cwd: The current working directory.
  • args: The first argument passed to core_d.invoke.
  • text: The second argument passed to core_d.invoke.
  • callback: A callback function with the signature (err, response).

The service can optionally implement a getStatus() function to return additional status information when calling core_d.status().

Moar speed

If you're really into performance and want the lowest possible latency, talk to the core_d server with netcat. This will also eliminate the node.js startup time on the client side.

❯ PORT=`cat ~/.core_d | cut -d" " -f1`
❯ TOKEN=`cat ~/.core_d | cut -d" " -f2`
❯ echo "$TOKEN $PWD file.js" | nc localhost $PORT

Or if you want to work with stdin:

❯ echo "$TOKEN $PWD --stdin" | cat - file.js | nc localhost $PORT

Compatibility

  • 6.0.0: node 12, 14, 16, 18 and 20
  • 5.0.0: node 12, 14 and 16
  • 4.0.0: node 12, 14 and 16
  • 3.0.0: node 10, 12 and 14
  • 2.0.0: node 10, 12 and 14
  • 1.0.0: node 6, 8 and 10

License

MIT