
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Keep your code piping hot! Live code reloading without additional binaries
There are already node "wrappers" that handle watching for file changes and restarting your application (such as node-supervisor), as well as reloading on crash, but I wasn't fond of having that. Piping adds "hot reloading" functionality to node, watching all your project files and reloading when anything changes, without requiring a "wrapper" binary.
Piping uses the node cluster API to spawn your application in a thread and then kill/reload it when necessary. Piping should not be used in production.
npm install piping
Piping is super simple to integrate and should not change the way you run your application:
require("piping")();
// Application logic here
express = require("express");
app = express();
app.listen(3000);
With the default settings, this will cause a second instance of your application to be launched, which is monitored by the first. Piping then does a trick with uncaughtException handling to avoid running any of your code on the first process.
The function returned by piping also accepts an options object. The following options are supported:
process.argv[1]
, which should be sufficient provided you launch your application via "node yourapp.js". Other launch methods may require this to be set manually. If your app doesn't reload/reloads when it shouldn't, try changing this./(\/\.|~$)/
Example:
require("piping")({main: "./app/server.js", hook:true});
// App logic
Piping can also be used just by passing a string. In this case, the string is taken to be the "main" option:
require("piping")("./app/server.js");
// App logic
Piping emits lifecycle events on both the supervisor and your application process, allowing for custom behavior. Most events provide the reloaders status, in the form:
{
exiting: boolean, // True if the process is about to reload
firstRun: boolean, // True on the first run of the application
exitReason: string? // Reason for last exit, one of "exited", "errored", "killed", "requested"
fileChanged: string? // Name of file which changed and triggered the last reload.
}
You can receive lifecycle events by passing in a function as the second parameter to the piping call, or the first if you are not specifying any options. This function will be called once everything is ready, and will be passed an EventEmitter. See the example below for supported events:
require("piping")(function(reloader){
reloader.on("started", function(status) {
// called on the first run of the application.
});
reloader.on("watch", function(file) {
// called when a file is added to the watch list by the require hook.
});
reloader.on("reloading", function(status) {
// called when the application is about to reload.
});
reloader.on("waiting", function(status) {
// called when the application has indicated it will reload.
});
reloader.on("reloaded", function(status) {
// called when the application has completed a reload.
});
reloader.on("exited", function(status) {
// called when the application exits unprompted.
});
});
On the application process, the piping call will return an EventEmitter. See the example below for supported events:
const reloader = require("piping")();
reloader.on("reload", function(done) {
// called when a reload is requested by the supervisor.
// You can use this to do any clean up required.
// If this event is handled by your application you need to call the done function to indicate your application can be restarted now.
});
reloader.on("reloaded", function(status) {
// called after a successful reload on the new application instance.
});
FAQs
Keep your code piping hot! Live code reloading without additional binaries
The npm package piping receives a total of 1,458 weekly downloads. As such, piping popularity was classified as popular.
We found that piping demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.