Security News
Internet Archive Hacked, 31 Million Record Compromised
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
node-localstorage
Advanced tools
A drop-in substitute for the browser native localStorage API that runs on node.js.
The node-localstorage npm package provides a simple way to emulate the browser's localStorage API in a Node.js environment. This is particularly useful for storing data persistently across sessions in a Node.js application.
Set Item
This feature allows you to store a key-value pair in the local storage. The data is saved persistently in the specified directory.
const { LocalStorage } = require('node-localstorage');
const localStorage = new LocalStorage('./scratch');
localStorage.setItem('myKey', 'myValue');
Get Item
This feature allows you to retrieve the value associated with a given key from the local storage.
const { LocalStorage } = require('node-localstorage');
const localStorage = new LocalStorage('./scratch');
const value = localStorage.getItem('myKey');
console.log(value);
Remove Item
This feature allows you to remove a key-value pair from the local storage.
const { LocalStorage } = require('node-localstorage');
const localStorage = new LocalStorage('./scratch');
localStorage.removeItem('myKey');
Clear Storage
This feature allows you to clear all key-value pairs from the local storage.
const { LocalStorage } = require('node-localstorage');
const localStorage = new LocalStorage('./scratch');
localStorage.clear();
The localStorage package provides a similar API to node-localstorage but is designed to be a more lightweight and minimalistic solution. It offers basic localStorage functionalities but may lack some of the more advanced features and configurability of node-localstorage.
The node-persist package offers a more feature-rich and flexible solution for persistent storage in Node.js. It supports various storage backends and provides additional features like data expiration and encryption, making it a more robust alternative to node-localstorage.
The electron-store package is designed specifically for Electron applications but can also be used in Node.js. It provides a simple API for persistent storage and supports JSON schema validation, making it a good choice for applications that require more structured data storage.
Copyright (c) 2012, Lawrence S. Maccherone, Jr.
A drop-in substitute for the browser native localStorage API that runs on node.js.
localStorage['myKey'] = 'myValue'
and dot property localStorage.myKey = 'myValue'
syntax. If you are in an ES6 supported environment. Limitations:
Author: Larry Maccherone
unless localStorage?
{LocalStorage} = require('../') # require('node-localstorage') for you
localStorage = new LocalStorage('./scratch')
localStorage.setItem('myFirstKey', 'myFirstValue')
console.log(localStorage.getItem('myFirstKey'))
# myFirstValue
localStorage._deleteLocation() # cleans up ./scratch created during doctest
Open or create src/setupTests.js
and add these two lines:
// /src/setupTests.js
import { LocalStorage } from "node-localstorage";
global.localStorage = new LocalStorage('./scratch');
if (typeof localStorage === "undefined" || localStorage === null) {
var LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./scratch');
}
localStorage.setItem('myFirstKey', 'myFirstValue');
console.log(localStorage.getItem('myFirstKey'));
Polyfil your node.js environment with this as the global localStorage when launching your own code
node -r node-localstorage/register my-code.js
npm install node-localstorage
new
FAQs
A drop-in substitute for the browser native localStorage API that runs on node.js.
The npm package node-localstorage receives a total of 177,612 weekly downloads. As such, node-localstorage popularity was classified as popular.
We found that node-localstorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
Security News
TC39 is meeting in Tokyo this week and they have approved nearly a dozen proposals to advance to the next stages.
Security News
Our threat research team breaks down two malicious npm packages designed to exploit developer trust, steal your data, and destroy data on your machine.