A tiny ES6 class for simulating localstorage browser behaviour in nodejs.
to install the package run:
npm install nodejs-localstorage-adapter --save
first include the package to your project:
var localStorage = require('nodejs-localstorage-adapter');
-Methods
-
for setting a value:
localStorage.setItem("user_id", "12345");
-
for getting a value:
var userId = localStorage.getItem("user_id"); // should return "12345"
-
returns the key name string for that index:
localStorage.setItem("user_id", "12345"); localStorage.setItem("user_name", "mark"); localStorage.key(0); // should return "user_id"
-
remove specific item:
localStorage.removeItem('user_id');
-
clear all items:
localStorage.clear();
-Properties
-
to get amount of key value pairs in localstorage:
localStorage.setItem('user_id', '12345'); localStorage.setItem('user_name', 'mark'); localStorage.setItem('user_age', '25'); localStorage.length; // should return 3