Registry / storage / cordova-plugin-nativestorage

cordova-plugin-nativestorage

JSON →
library2.3.2jsnpmunverified

A Cordova plugin for native persistent storage on Android (SharedPreferences), iOS (NSUserDefaults), Windows, and OS X. Version 2.3.2 is the latest stable release. It provides a simple key-value API similar to localStorage but with data persistence guaranteed by the native platform. Unlike localStorage, data is not cleared on low memory. Supports strings, numbers, booleans, arrays, and objects. The plugin is maintained but updates are infrequent; last release was in 2018. Contains known vulnerabilities (CVE-2018-19195) due to older dependencies.

npm install cordova-plugin-nativestorage
INSTALL
IMPORT
SIG · CORDOVA-PLUGIN-NAT
C
cordova-plugin-nativestorage
storagejavascriptv2.3.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NativeStorage
window.NativeStorage
import NativeStorage from 'cordova-plugin-nativestorage'
This plugin does not support ES module imports; use the global window object after deviceready.
NativeStorage.setItem()
NativeStorage.setItem('key', 'value', successCallback, errorCallback)
NativeStorage.setItem('key', 'value')
Promises are not supported; you must provide callbacks.
NativeStorage.getItem()
NativeStorage.getItem('key', successCallback, errorCallback)
NativeStorage.getItem('key').then(...)
Returns via callbacks, not promises.

Demonstrates basic set, get, remove, and clear operations using the global NativeStorage object with callbacks.

// Wait for Cordova to be ready document.addEventListener('deviceready', function() { // Store a value NativeStorage.setItem('mykey', {hello: 'world'}, function(result) { console.log('Stored:', result); }, function(error) { console.error('Error storing:', error); }); // Retrieve a value NativeStorage.getItem('mykey', function(value) { console.log('Retrieved:', value); }, function(error) { console.error('Error retrieving:', error); }); // Remove a value NativeStorage.remove('mykey', function() { console.log('Removed'); }, function(error) { console.error('Error removing:', error); }); // Clear all NativeStorage.clear(function() { console.log('Cleared'); }, function(error) { console.error('Error clearing:', error); }); }, false);
Debug
Known issues
breakingPlugin is only available after deviceready event; calling methods too early will fail silently.
fix
Always wrap NativeStorage calls inside document.addEventListener('deviceready', function() { ... });
affects: >=2.0.0
deprecatedThe plugin uses callbacks, not Promises. No built-in Promise support.
fix
Wrap calls in a Promise manually or use a wrapper library.
affects: <3.0.0
gotchaKeys are case-sensitive and must be strings. Overwriting a key with a different type may cause unexpected behavior.
fix
Always use consistent key names and types.
affects: all
gotchaWindows platform requires 'windows-target-version' to be set to 10.0.16299.0 or higher.
fix
Check Windows SDK version and update if necessary.
affects: >=2.2.0
Errors
Common errors & fixes
NativeStorage is not defined
Attempting to use NativeStorage before deviceready event or without plugin installed.
fix
Ensure plugin is added (cordova plugin add cordova-plugin-nativestorage) and wrap code in deviceready listener.
TypeError: NativeStorage.setItem is not a function
Using wrong import (e.g., import from npm) instead of relying on global window.NativeStorage.
fix
Remove any import statements; use window.NativeStorage after deviceready.
NativeStorage: [error] - Not Found
Trying to get a key that does not exist.
fix
Check if key exists before retrieval, or handle error callback gracefully.
Upgrade
Version history
2.3.2latest on npm
Audit
Dependencies
cordovarequiredCordova framework required for plugin usage
Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources
cordova-plugin-nativestorage — npm install cordova-plugin-nativestorage · libregistry