Recent Changes - Search:

edit SideBar

LocalStorage

The localStorage module is a JavaScript module providing persistent key-value storage based on local files. This is mainly intended to be compatible with the node-persist module in node.js. As other optional modules in Node.js, we need to call the require() function to use this module as follows.

var storage = require('localStorage');
storage.initSync();
storage.setItem('key0', 'value0');

The functions provided in this module are:

  • localStorage.initSync(opts): This must be called before calling any other functions. Set up a new persistent storage in the file system.
  • localStorage.getItem(key): Take a key and return its value from the local storage if the key exists, otherwise, return null.
  • localStorage.setItem(key, value): Take a key-value pair and store the pair into the local storage.
  • localStorage.removeItem(key): Take a key and remove it from the local storage.
  • localStorage.clear(key): Remove all keys in the local storage.
  • localStorage.key(n): Return a key with index n, or null if it is not present.
  • localStorage.length(): Return the number of keys stored in the local storage.

Back to Optional JavaScript Modules

Edit - History - Print - Recent Changes - Search
Page last modified on November 25, 2014, at 09:21 AM