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

file-store-sync

v0.1.0

Published

Store data in a file synchronously

Downloads

3

Readme

File-Store-Sync

Store and retrieve synchronously, primitive and objects javascript values in/from a plain text file.

Installation

$ npm install file-store-sync

Main concepts

File-store-sync store and retrieve synchronously primitive and objects javascript values into/from a plain text file.

All the values are reference by a key, and the module internally use a javascript object where all the values are added, removed or read as properties, so the property name is the used key and its value, the key's value.

Each operation read the content of the file, parse the content as a JSON data to get a plain javascript object, read/modify/delete the value using the key (property's name), transform the javascript object to JSON and write (entirely) the JSON value into the file. Due to this simple way to manage the file content and the I/O operations are synchronously, this module is not appropriated to manage a big amount of data but it may useful to persist some data and retrieve afterwards for example if you application is stopped or if another process need to access to that data and those process cannot continue executing the next instructions until they have read that data.

How to use

Simply the module return a constructor that receive as a unique parameter the path to the file to use and just execute the operations that you need. Remember, no callbacks, all the operations are synchronously.

var FileStoreSync = require('file-store-sync');
var store = new FileStoreSync('./store-test');

API

  • get(key) - Return the value associated with the key
  • set(key, value) - Set or override the value associated with the key
  • push(key, value) - Add a value to the array associate with the key
  • pushIfNotExists(key, value) - Add a value if it doesn't exist into the array associated with the key
  • remove(key, value) - Remove the value from the array associated with the key
  • remove(key, value) - Remove the value associated with the key

Example


'use strict';

var FileStoreSync = require('file-store-sync');
var store = new FileStoreSync('./store-test');

store.push('array-key', 'array-value');

store.pushIfNotExists('array-key', 'array-value');

console.log('The value of array-key is: ' +  store.get('array-key'));

store.set('key', { some: 'value' });

console.log('The value of key is: ' +  store.get('key'));

store.remove('array-key', 'array-value');

console.log('Now array-key is: ' +  store.get('array-key'));

store.delete('key');

console.log('Now the value of key is: ' +  store.get('key'));

Acknowledgements

I would like to appreciate to Raynos to develop the file-store project and release that under MIT license.

LICENSE

License (The MIT License)

Copyright (c) 2013 Ivan Fraixedes Cugat [email protected]

This project is a fork from the project file-store developed Raynos (https://github.com/Raynos/file-store)

Copyright (c) 2012 Raynos.