Nagging Penguin Matriarchs
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »


2.0.0 • Public • Published

npm npm npm


A NativeScript plugin to add LocalStorage and SessionStorage If you are trying to use any libraries that use the localStorage/sessionStorage API; or you want a fairly simple storage engine; here it is.


This is released under the MIT License, meaning you are free to include this in any type of program -- However for entities that need a support contract, changes, enhancements and/or a commercial license please contact me at

I also do contract work; so if you have a module you want built for NativeScript (or any other software projects) feel free to contact me

Donate Patreon

Sample Snapshot



Supports NativeScript 2.x and greater

Breaking Change from v1 to v2

  • V2.00 now forces setItem to be the same as a browser, browsers ONLY allow strings. If you would like the old behavior; use setItemObject instead of setItem which is an enhancement and allows all JavaScript types to be stored.


tns plugin add nativescript-localstorage


To use the module you just require() it:

require( "nativescript-localstorage" );
localStorage.setItem('Another Plugin', 'By Master Technology');

This will enable the localStorage api. So then you can use it just like a browser.

You can also optionally do:

let LS = require( "nativescript-localstorage" );
LS.getItem('Another Plugin');  // Returns: "By Master Technology"

You ask, how exactly does this help?

This allows you to use localStorage or sessionStorage as if it is built into NativeScript.


localStorage.getItem(name) - Get a value from Storage

name - the key to get

This will return whatever you stored in that key, or null if that key doesn't exist.

let me = localStorage.getItem('MeaningOfLife') || 42;

localStorage.setItem(name, value) - Set a STRING value into storage

name - the key to set
value - the value to set; this can be number or string. Will auto-convert to string.
localStorage.setItem('Zork', 'You are about to be eaten by a Grue!');

localStorage.setItemObject(name, value) - Sets a value into storage

name - the key to set
value - the value to set; this can be number, string, object, array. (Must be a native JavaScript object)
localStorage.setItem('Zork', {result: 'You are about to be eaten by a Grue!'});

localStorage.removeItem(name) - Delete and item from storage

name - the key to delete
localStorage.removeItem('Zork');  // Guess you were eaten and removed!  :-)

localStorage.clear() - clear all storage


localStorage.length - Number of items stored

Returns the number of keys stored

console.log("Keys stored", localStorage.length);

localStorage.key(id) - Return the key name at this position

id - 0 based id of the key
returns: string name of the key (or null if id is past size of saved storage )
console.log("Key at 0 is", localStorage.key(0));


You can use sessionStorage instead of localStorage for any of the routines above; the difference between the two API's is localStorage saves and will always be present, where sessionStorage is temporary, when you close the program it is gone.



npm i nativescript-localstorage

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability