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

jsonwatch

v1.1.0

Published

Json file reader, which will emit events on the Json file content. It will also watch your Json file for any changes and emit events which will tell you about the changes. This module was intended for reading/watching configuration files which may change while running an app.

Downloads

4

Readme

jsonwatch

Json file reader, which will emit events on the Json file content. It will also watch your Json file for any changes and emit events which will tell you about the changes. This module was intended for reading/watching configuration files which may change while running an app.

Getting started

First, require() jsonwatch and load your Json file

var JsonWatch = require('jsonwatch');
var config = new JsonWatch('./config.json');

Now, you should add listeners for your Json structure.

Methods

.on(event, fn)

Register an event handler fn.

.once(event, fn)

Register a single-shot event handler fn, removed immediately after it is invoked the first time.

.off(event, fn)

Remove event handler fn, or pass only the event name to remove all handlers for event.

.listeners(event)

Return an array of callbacks, or an empty array.

.hasListeners(event)

Check if this emitter has event handlers.

Events

add event

Something was added to the Json.

Event arguments:

  1. The path to what was added.
  2. The value that was added.

cng event

Something in the Json was changed.

Event arguments:

  1. The path to what was changed.
  2. The value that was before the change.
  3. The value after the change.

err event

There was an error.

Event arguments:

  1. An Error.

rm event

Something was removed from the Json.

Event arguments:

  1. The path of what was removed.
  2. The value that was removed.

Paths in the Json

{
 "users": {
   "alfred": {
     "password": "qwerty"
   },
   "olof": {
     "password": "123456",
     "aliases": [ "olle", "lol", "floflo" ]
   }
 }
}

When loading the Json above, those events will be emitted:

  1. add, with arguments: 1. "/users" and 2. {}
  2. add, with arguments: 1. "/users/alfred" and 2. {}
  3. add, with arguments: 1, "/user/alfred/password" and 2. `"qwerty"``
  4. add, with arguments: 1. "/users/olof" and 2. {}
  5. add, with arguments: 1, "/user/olof/password" and 2. `"123456"``
  6. add, with arguments: 1. "/user/olof/aliases" and 2. [ "olle, "lol", "floflo" ]

So, the paths are made from Json object keys. Any other type in a Json will become the "value".