jsoning
A simple key-value JSON-based persistent lightweight database.
View Demo · Report Bug · Request Feature
Loved the project? Please consider donating to help it improve!
Like us a lot? Help others know why you like us! Review this package on pkgreview.dev | ![]() |
![]() |
---|
Features
- Uses JSON files to modify and write key-value elements as JSON-objects.
- Easy to use and lightweight.
- Prevents JSON corruption with atomic file writing.
- Uses a single dependency (
write-file-atomic
)
Install
Node.js v12.x or greater is required for this package to work.
npm install jsoning
View the full documentation here.
Basic Usage
let jsoning = require("jsoning");
let db = new jsoning("database.json");
(async() => {
// set some values with a key
await db.set("birthday", "07-aug");
await db.set("age", "13");
// push stuff to an array for a particular key
await db.push("transformers", "optimus prime");
await db.push("transformers", "bumblebee");
await db.push("transformers", "iron hide");
// simply log what get is (i forgot what the transformers were)
console.log(await db.get("transformers")); // [ 'optimus prime', 'bumblebee', 'iron hide' ]
// just want to see what all is there
console.log(await db.all()); // { object of the whole database contents }
// does such a value exist
console.log(await db.has("value2")); // false
// my age keeps changing, so I'm deleting it
console.log(await db.delete("age")); // true
// i got 100$ for my birthday
await db.set("money", 100);
// and someone gave me 200 more dollars xD
await db.math("money", "add", 200);
// just wanna make sure how much money I got
console.log(await db.get("money")); // 300
// i'm getting bored, so i'm clearing the whole database
await db.clear();
})();
Links
Contributing
Please see CONTRIBUTING.md
for more details on contributing!
Contributors
Thanks goes to these wonderful people (emoji key):
Khaleel Gibran 💻 📖 🎨 🚇 ⚠️ ✅ |
David 📖 |
Jonyk56 💻 |
ayntee 💻 |
undefine 💻 🐛 🛡️ |
This project follows the all-contributors specification.
Contributions of any kind are welcome!
License
This package is open sourced under the MIT License.