0.1.5 • Published 8 years ago

persistent-counter v0.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

PersistentCounter

A simple counter with persistent storage

npm Build Status npm

Installation

$ npm install persistent-counter

Usage

Create a persistent counter, and optionally provide a writeInterval in milliseconds. Increment at will, and the incremented value will be automatically flushed to disk every writeInterval milliseconds.

If your program exits without calling flush(), any increments since the last timer-triggered write will be lost.

The current count can be accessed by the count property.

Example

let PersistentCounter = require('persistent-counter');

let pc = new PersistentCounter({
  filename: 'path/to/count.json',
  writeInterval: 5 * 60 * 1000
});

pc.increment();
console.log(pc.count);

pc.flush();

Caveats

This is a lightweight solution for a single process. I haven't tested it with multiple processes on the same file, and I expect that it wouldn't work right, and could possibly corrupt data.

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.3-0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.1.0-1

8 years ago