A drop-in substitute for the browser native localStorage API that runs on node.js.
CoffeeScript
461
174 commits
updated Oct 19, 2023
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 publishnewOverall
Maintained
Code review
Latest release
Releases this year
13 followers · starred Apr 2019
661 followers · starred Aug 2020
A drop-in substitute for the browser native localStorage API that runs on node.js.
CoffeeScript
461
174 commits
updated Oct 19, 2023
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 publishnewOverall
Maintained
Code review
Latest release
Releases this year
13 followers · starred Apr 2019
661 followers · starred Aug 2020