Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

core_d

mantoni125.7kMIT6.1.1

Offload your heavy lifting to a daemon

daemon, service, background

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

changelog

Changes

6.1.1

  • 🐛 5c45150 fix: UTF8 support (#32) (Alex Efros)

Released by Maximilian Antoni on 2025-08-04.

6.1.0

  • 🍏 b3b36ba feat: added debug with flag (#27) (Amrit Kahlon)
  • 📚 e1f489a Update compatibility notes
  • 7f10fd1 npm audit
  • 5b6615a Upgrade mocha to v10
  • 0df0d6d Update eslint-plugin-mocha
  • def70eb Update eslint
  • a21e74b Update GitHub action
  • e8960ee Support node 18 and 20
  • 88e407c Upgrade referee-sinon

Released by Maximilian Antoni on 2023-11-10.

6.0.0

  • 💥 d76e925 fix: write errors to stderr (#26) (fsouza)

Released by Maximilian Antoni on 2023-09-22.

5.0.1

  • 📚 31fc5e6 Fix API documentation

Released by Maximilian Antoni on 2022-05-26.

5.0.0

  • 💥 ded6fe6 BREAKING: Remove broken package manager file checks
  • 🛡 e7fe811 Bump minimist from 1.2.5 to 1.2.6 (dependabot[bot])

Released by Maximilian Antoni on 2022-05-26.

4.0.0

  • 💥 b198007 Invoke service with content hash of package files rather than last modification time (Dara Dermody)
  • 💥 43dcca2 Drop node 10, support node 16
  • 📚 d476ed6 Document node 16 support
  • b1bd3a1 Upgrade eslint, eslint-config and plugins
  • fff26f0 Upgrade referee-sinon
  • 63e98b7 Upgrade mocha
  • 🛡 6c23271 npm audit

Released by Maximilian Antoni on 2022-02-16.

3.2.0

  • 🍏 12c60c8 XDG Compliance (#14) (Jaden Pleasants)

Released by Maximilian Antoni on 2021-05-10.

3.1.0

  • 🍏 c5b2d8d Handle exit code sent by service (Jose Alvarez)
  • 🛡 96f5ca5 Bump hosted-git-info from 3.0.4 to 3.0.8 (dependabot[bot])
  • 🛡 d81a0e7 Bump lodash from 4.17.19 to 4.17.21 (dependabot[bot])
  • 51d547d Update eslint
  • f1b707e Update Studio Changes
  • 1d1db24 Update mocha
  • ed45678 Upgrade referee-sinon to latest
  • 20e3cfc Run GitHub actions on PRs
  • 📚 bfe1f7c Change badge

Released by Maximilian Antoni on 2021-05-09.

3.0.0

  • 💥 96dc4a1 Breaking: Pass callback to invoke for result handling
  • 📚 2ff6e0a Add compatibility notes for v3
  • 📚 16f1680 Document invoke API change
  • 423d95b Ugrade referee-sinon
  • 544a718 Update mocha
  • bed840f Update eslint
  • 88ff76c Upgrade supports-color to v8
  • 4f74cdf Remove Travis config
  • 0802f5f Configure GitHub actions
  • 2ad5a48 Bump lodash from 4.17.15 to 4.17.19 (dependabot[bot])

Released by Maximilian Antoni on 2021-01-11.

2.0.0

  • 💥 340640b Drop node 6 and 8 support, add node 12 and 14
  • 📚 eee1f06 Update compatibility notes for v2.0.0

Released by Maximilian Antoni on 2020-06-22.

1.1.0

Released by Maximilian Antoni on 2020-06-22.

1.0.1

  • 🐛 857bb3b Add missing supports-color dependency

Released by Maximilian Antoni on 2019-02-28.

1.0.0

Released by Maximilian Antoni on 2019-02-26.