node-lstorage
v1.0.7
Published
Simple storage library with temp file options for [node.js](https://www.npmjs.org)
Downloads
3
Maintainers
Readme
LocalStorage
Simple storage library with temp file options for node.js
Why?
I so many times needed a simple local storage or temp storage and it simplify all the process.
Installation
npm install node-lstorage
Usage
It's so easy to use.
First you need to define it:
const storage = require('node-lstorage'); // I recommend use `storage` name for var.
Simple
let notifications = false;
(function main() {
storage.load();
if(storage.has('notifications')) {
notifications = storage.get("notifications");
} else {
storage.set("notifications", notifications);
}
console.log(notifications);
})();
Change File Name
let notifications = false;
(function main() {
storage.load("json_files/change_file");
if(storage.has('notifications')) {
notifications = storage.get("notifications");
} else {
storage.set("notifications", notifications);
}
console.log(notifications);
})();
Save Multiple Data
let notifications = false;
let normal_width = 800;
let normal_height = 1024;
(function main() {
storage.load("json_files/save_multiple_data");
if(!storage.has([ 'notifications', 'normal_width', 'normal_height' ])) {
console.log("All variables setted.");
storage.set({
notifications: notifications,
normal_width: normal_width,
normal_height: normal_height
});
}
if(storage.has('notifications')) {
notifications = storage.get("notifications");
} else {
storage.set("notifications", notifications);
}
if(storage.has('normal_width')) {
normal_width = storage.get("normal_width");
} else {
storage.set("normal_width", normal_width);
}
if(storage.has('normal_height')) {
normal_height = storage.get("normal_height");
} else {
storage.set("normal_height", normal_height);
}
console.log({
notifications: notifications,
normal_width: normal_width,
normal_height: normal_height
});
})();
Temp file system
let notifications = false;
(function main() {
storage.tmp(); // Initialize temp storage system
if(storage.tmp.has('notifications')) {
notifications = storage.get("notifications");
} else {
storage.tmp.set("notifications", notifications);
}
console.log("\r\n");
console.log("FileName:", storage.tmp.fileName);
console.log("StorageData:", JSON.stringify(storage.tmp.data));
storage.tmp.delete(); // Delete temp file
console.log("TMP File deleted.");
})();
Properties
| Property | Description |
|:--- |:--- |
|data
| JSON file data as object. |
|lFile
| Used JSON file path. |
Methods
| Property | Description | Params |
|:--- |:--- |:--- |
|get
| JSON file data as object. |String
Property|
|set
| Set JSON property value. |(String
) Property, (Any
) Value OR (Object
) Values |
|has
| Verify JSON property exists. |(String
|Array
) Property |
|load
| Load JSON file data. |(String
) JSON File Path|
|empty
| Empty JSON file. | |
|tmp
| Instance temp file system subclass.| |
TMP Subclass methods
| Property | Description | Params |
|:--- |:--- |:--- |
|get
| Temp JSON file data as object. |String
Property|
|set
| Set temp JSON property value. |(String
) Property, (Any
) Value OR (Object
) Values|
|has
| Verify temp JSON property exists. |(String
|Array
) Property |
|delete
| Delete temp JSON file. | |