Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
daemonctrl
Advanced tools
Readme
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]
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
.
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);
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.
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();
});
Stops listening. You should run this on process SIGINT
, SIGTERM
, and exit
.
Removes the command from process.argv
if you use something that complains about invalid flags (like node-flags
),
run this first.
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
.
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
FAQs
Command-line control your Node.js daemon
The npm package daemonctrl receives a total of 8 weekly downloads. As such, daemonctrl popularity was classified as not popular.
We found that daemonctrl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.