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

hotter

v0.0.1

Published

Keep your code piping hot! Live code reloading without additional binaries

Downloads

5

Readme

Piping

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 currently unstable "cluster" API to spawn your application in a thread and then kill/reload it when necessary. Because of this, piping should be considered unstable and should not be used in production (why would you ever need live code reloading in production anyway). Currently, at least on windows, the cluster API seems stable enough for development.

Also check out piping-browser which does a similar job for the browser using browserify

Installation

npm install piping

Usage

Piping is not a binary, so you can continue using your current workflow for running your application ("wooo!"). Basic usage is as follows:

if (require("piping")()) {
  // application logic here
  express = require("express");
  app = express();
  app.listen(3000);
}

or in coffeescript:

if require("piping")()
  # application logic here
  express = require "express"
  app = express()
  app.listen 3000

This if condition is necessary because your file will be invoked twice, but should only actually do anything the second time, when it is spawned as a separate node process, supervised by piping. Piping returns true when its good to go.

the function returned by piping also accepts an options object. The following options are supported:

  • main (path): The path to the "top" file of your application. Defaults to require.main.filename, 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.
  • hook (true/false): Whether to hook into node's "require" function and only watch required files. Defaults to false, which means piping will watch all the files in the folder in which main resides. The require hook can only detect files required after invoking this module!
  • includeModules (true/false): Whether to include required files than reside in node_modules folders. Defaults to false. Only has an effect when hook is true. For ignoring node_modules when hook is false, please use ignore.
  • ignore (regex): Files/paths matching this regex will not be watched. Defaults to /(\/\.|~$)/
  • language (string): The name of a module that will be required before your main is invoked. This allows for "coffee-script" to be specified to support a coffeescript main, launchable though "coffee". Probably works for other languages as well. Coffeescripters don't actually need this, as coffee-script is required automatically if main is a .coffee file.
  • usePolling (true/false) : From chokidar. Default false. Whether to use fs.watchFile (backed by polling), or fs.watch. It is typically necessary to set this to true to successfully watch files over a network.
  • interval (true/false) : From chokidar. Polling specific. Interval of file system polling (default 100).
  • binaryInterval (true/false) : From chokidar. Polling specific. Interval of file system polling for binary files.
  • respawnOnExit (true/false) : Default true. Whether the application should respawn after exiting. If you experience problems with infinite loops, try setting this to false.

Example:

if (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:

if (require("piping")("./app/server.js")){
  // app logic
}

One negative of all the examples above is the extra indent added to your code. To avoid this, you can choose to return when piping is false:

if (!require("piping")()) { return; }
// application logic here

or in coffeescript:

if not require("piping")() then return
# application logic here