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

@krakenjs/grabthar

v6.2.0

Published

Periodic npm installs in production

Downloads

49

Readme

build status code coverage npm version apache license

Do it live

Because npm installing in production every 30 seconds is a great idea, right? ...right?

Quick Start

npm install --save @krakenjs/grabthar

Examples

Hot deploy and serve up static files:

import { poll } from "@krakenjs/grabthar";

let watcher = poll({
  name: "my-live-updating-module",
});

app.get("/foo.js", async function handleRequest(req, res) {
  const { modulePath } = await watcher.get();
  res.sendFile(`${modulePath}/dist/foo.js`);
});

Or if you're feeling really brave, hot deploy and require new code:

import { poll } from "@krakenjs/grabthar";

let watcher = poll({
  name: "my-live-updating-module",
});

app.get("/api/foo", async function handleRequest(req, res) {
  const { getFoo } = await watcher.import();
  res.json(getFoo());
});

Deploying

By default grabthar will use the current latest tag of your chosen module, from npm.

So, to deploy and activate new code, just:

npm version patch;
npm publish;

This will automatically set the latest tag to the latest version.

Deploying and activating in different steps

To separate out the deployment and activation of new code, you can make use of different npm dist-tags:

import { poll } from "@krakenjs/grabthar";

let watcher = poll({
  name: "my-live-updating-module",
  tags: ["latest", "release"],
});

app.get("/foo.js", async function handleRequest(req, res) {
  const { modulePath } = await watcher.get("release");
  res.sendFile(`${modulePath}/dist/foo.js`);
});

To deploy:

npm version patch;
npm publish;

To activate:

npm dist-tag add [email protected] release

grabthar will monitor and install anything passed in tags, but the activated version will only change when you set a new release dist tag.

Rolling back to old versions

Just change the dist-tag to whatever version you want to roll back to:

npm dist-tag add [email protected] latest

or:

npm dist-tag add [email protected] release

What else will watcher.get() return?

const {
  // The root directory where the module is installed, e.g.
  // /Users/zippy/__live_modules__/my-live-updating-module_1.3.53
  moduleRoot,

  // The full path to the node_modules installed, e.g.
  // /Users/zippy/__live_modules__/my-live-updating-module_1.3.53/node_modules/
  nodeModulesPath,

  // The full path to your module, e.g.
  // /Users/zippy/__live_modules__/my-live-updating-module_1.3.53/node_modules/my-live-updating-module
  modulePath,

  // The semver version of your module that is currently installed and activated, e.g.
  // 1.3.53
  version,

  // A map of the dependencies of your module, e.g.
  // { foo: '1.2.3', bar: '0.45.2' }
  dependencies,
} = await watcher.get();

How can I cancel a watcher?

watcher.cancel();

Tests

  • Run the tests:

    npm test