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

daemonctrl

v0.0.7

Published

Command-line control your Node.js daemon

Downloads

4

Readme

daemonctrl

Control your daemon via the command line. A command is the first word sent after the flags passed to a node script. The commandArgs is anything after the command and is not split on spaces.

Example: node send.js --flags [command] [commandArgs]

Docs

socketOptions(options)

Allows you to set options for how the socket is setup. This should be sent with the same params from the daemon and sender.

Options are path, ip, port.

send(endListener)

Sends the command sent in the args to the daemon. endListener is added as a listner for end which fires when the command is sent. send can return falsey if no command was sent (or start was sent and we're not spawning). See the Notes section for why. If this fires the error event with the code ECONNREFUSED then the daemon probably isn't running.

To pipe the response back to another stream (like stdout) just run:

daemonctrl.send().pipe(process.stdout);

fork(modulePath)

Tells send() to fork when the start command is sent and return an instance of ChildProcess. The endListener is fired with a ChildProcess. If one of the arguments sent to the calling process is -fork or --fork we will *NOT pass that to the forked child as a helper to prevent infinite forking.

listen(listeningListener)

This command is run from the daemon itself on start. When listening is fired you can start running your app. listeningListener is added as a listener for the listening event. If this fires the error event with the code EADDRINUSE then the daemon is probably already running.

The command event is fired when a command is received. The listeners are sent (command, commandArgs, socket). You can respond to the sender by writing to the socket. You are required to end the socket.

Example:

daemonctrl.listen(function() {
    myApp.run();
});

end()

Stops listening. You should run this on process SIGINT, SIGTERM, and exit.

strip()

Removes the command from process.argv if you use something that complains about invalid flags (like node-flags), run this first.

timeout(newTimeoutMS)

Sets the timeout on the listening side for getting a response back from the server. Defaults to 5000. On timeout, the send emitter emits error.

Notes

If you want to use the same script for sending and starting you just need to check to see if send returned a falsey value.

var sender = daemonctrl.send();
if (sender) {
    //send command to daemon
    sender.pipe(process.stdout);
    //beforeExit gets called when the event-loop is exausted which means the socket closed
    process.on('beforeExit', function() {
        process.stdout.write("\n");
    });
    return;
}
//running in the daemon since no command (or command was "start") was sent 
daemonctrl.listen(function() {
    myApp.run();
});

By James Hartig