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

isync

v1.0.6

Published

A straightforward and zero-dependency NodeJS module to automatically persist JavaScript objects to disk at intervals, in JSON.

Downloads

7

Readme

isync

A straightforward and zero-dependency NodeJS module to automatically persist JavaScript objects to disk at intervals, in JSON.

npm version

Released under the terms of the Beerware license.

Contact me on Telegram at @kuvam.

Installation

npm install isync --save

Usage

1. Load isync.

const isync = require('isync')

2. Create an instance of isync. (If the file already exists, isync will attempt to synchronously parse it as JSON to the data property.)

const store = new isync('./store.json')

3. (a) Use the data property as a plain-jane JavaScript object.

store.data.x = "foo"
store.data.y = [3, "bar", false]
store.data.z = { baz: store.data.x + "d", _: [null] }

3. (b) Alternatively, set it to an existing object you want to persist.

const blob = { pi: 22 / 7, e: [2, 7, 1, 8] }
store.data = blob

4. The data object will be automatically synced at the specified interval (defaults to 10 minutes if unspecified) while your NodeJS program is running.

5. Before exiting, flush any last-minute changes manually using flushSync().

store.flushSync()

Details

1. An instance of isync is initialised with this constructor signature.

new isync(path: String, period?: Number)

The period is specified in minutes and optional (defaults to 10 minutes).

2. Instances expose the following properties.

path

File path which this isync instance saves the data object to. Change it by assigning a new file path to this property.

data

A regular JavaScript object, which is serialised as JSON and synced to the file path specified. Properties which aren't JSON-serialisable won't be saved to disk.

period

The interval in minutes at which to flush the data object to disk. Change this interval by setting this property; its value will be used from the next sync onwards.

3. Instances expose the following methods.

unlink()

Stops syncing the data object to disk at intervals. You can still use it as you would, but changes since the last sync won't be saved automatically.

link()

Restarts syncing the data object, after a call to unlink(). (You don't need to call this if you haven't unlinked the instance; by default, newly initialised instances of isync will be syncing automatically.)

flushSync()

Force a synchronous (thread blocking) flush of the data object to disk, even if the instance is unlinked. It is necessary to call this before your NodeJS application exits, unless you're absolutely sure there have been no changes to data since the last sync.

flush(link: Boolean)

An asynchronous (non-blocking) call to save the data object to disk, even if the instance is unlinked. If the link parameter is set, calls link() on this instance after completion.

Bear in mind that you can't await this call; however, you can listen on the next 'flush' event after making this call to proceed whenever the flush is completed.

4. You can listen on 'flush' events on an isync instance (store in this example) using idiomatic NodeJS events.

store.on('flush', callback)

This event is emitted on completion of both manual and automatic syncs. You can use it to confirm that data has been saved to disk successfully or to log disk syncs.

❤️   June, 2017  –  March, 2019.