Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.15 KB

readme.md

File metadata and controls

59 lines (44 loc) · 1.15 KB

node-localstorage

A lightweight library that allows you to add simple file storage to your nodeJS project

const Storage = require("node-localstorage");

const storage = new Storage("./storage");

storage.addItem("name", "any type value");

Install

npm i --save https://github.com/Kaddlee/node-localstorage.git

Methods

// ADD new item
// If such a key is found, it will be overwritten
storage.addItem("name", "any type value");

// GET item
storage.getItem("name");

// REMOVE item
storage.removeItem("name");

// REWRITE storage file
storage.rewrite({name: "Kaddlee"}); // default {name: "Kaddlee"}
storage.rewrite(); // default {}

Events

You can call this events with your custom callback

// ADD item event
storage.on('add', (item) => {
  console.log(`You add ${item.name} with value ${item.value}`);
})

// GET item event
storage.on('get', (item) => {
  console.log(item);
})

// REMOVE item event
storage.on('remove', (item) => {
  console.log(`You remove ${item.name} with value ${item.value}`);
})

// REWRITE item event
storage.on('rewrite', (status) => {
  if (status) console.log('Realy rewrite storage file!');
})