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

live-json-file

v0.2.0

Published

Creates a live saved version of an object

Downloads

20

Readme

live-json-file

Have you ever had to constantly write and read to a JSON file. Well this is the module for you.

This module takes the hassle out of reading and writing json files. You simply treat the file as any standard object with this simple module.

Sample Code

With the following code, the files "file.json" and "file2.json" is bound to the variables "obj" and "obj2" respectively. Everytime you update the object as follows the file updates.

var livefile = require('live-json-file');

var obj = new livefile.Object("file.json");
var obj2 = new livefile.Object("file2.json");

obj.o.a = "obj 1";
obj2.o.a = "obj 2";
obj.o.b = "obj 1";
obj2.o.b = "obj 2";

Current Major Issues

As any BETA software it is not without its flaws. The reason for these errors is due to the fact that JS is not intended to work this way and a lot of workarounds are in place to make it work.

The file does not update immediately. Once a change has been made to a field of the object then 1 more change or closing the program is require after that to save it to the file. i.e, in the above example obj.a is not saved on the file till obj.b is changed. and obj.c is not updated till the program terminates. This is a flaw due to the workaround used on the JS getter.

Updates

v0.2 A version of the program is added to allow the use of the ES6 feature 'proxies'. This eliminates all of the known issues so far. To use the extra features then the 'harmony' tags must be made on startup as follows

node --harmony --harmony_proxies my_program.js

The code itself is only slightly different

var livefile = require('live-json-file');

var obj = livefile.ObjectProxy("file.json");
var obj2 = livefile.ObjectProxy("file2.json");

obj.a = "obj 1";
obj2.a = "obj 2";
obj.b = "obj 1";
obj2.b = "obj 2";

The use of the 'o' parameter is no longer necessary and the file updates immediately after the object is updated.

v0.1 Multiple files can now be created