Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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._sync()
files can be re-read from disk. This is useful if you are using more
than one process to access the same storage location.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
_sync()
(thanks @create3000 for the report)_sync()
method (thanks @NexusNull)npm publish
new
FAQs
A drop-in substitute for the browser native localStorage API that runs on node.js.
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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.