You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

json-autosave

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-autosave

Automatically save a JSON-serializable object.

1.1.2
latest
Source
npmnpm
Version published
Weekly downloads
39
-57.14%
Maintainers
1
Weekly downloads
 
Created
Source

I have mutable state that must be kept after restarts.

I use…

json-autosave

  • Automatically save a JSON-serializable state on disk in the background.
  • Minimizes disk IO operations.
  • Resilient to process and system crashes (on journaling and COW file systems).
var autosave = require('json-autosave');
var stats = autosave('stats.json');

stats.data = { pageViews: 0 };

Interface

autosave(filename, options) returns a JsonSave object.

Options:

  • interval: how frequently (in milliseconds) we should ensure that the data is saved.
  • data: default data if it does not already exist.

save.data: mutable JS object that will be saved to JSON on disk automatically. You can set it to whatever you like or change any property it has. The only restriction is that it must be JSON-serializable.

save.setInterval(ms) changes the frequency with which we save the data.

save.stop() prevents saving data updates to disk.

save.start() resumes saving data to disk.

Keywords

JSON

FAQs

Package last updated on 05 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts