
Company News
Socket Has Acquired Secure Annex
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.
@tusent.io/json-database
Advanced tools
A super lightweight synchronous database/settings module for local storage of key-value data.
A Node.js module for storing data in files on the local machine. It's basically a settings manager.
This is only meant to be used by a single application since it doesn't automatically reload the file after another application has edited it. When it saves the file, it rewrites the entire file to disk.
json-database is available for installation through npm using the npm install command.
npm install @tusent.io/json-database --save
const Database = require('json-database');
// Load existing database or create
const db = new Database('./data.json');
// Gets with specified defaults
let dataVersion = db.get('dataVersion', Number.MIN_SAFE_INTEGER);
let userCount = db.get('userCount', 0);
/**
* If performance is not of the essence:
*/
if (dataVersion < 7) {
// Save backup file to './data.json.bak'
db.save(db.path + '.bak');
for (let i = 0; i < userCount; i++) {
let username = db.get(`users.${i}.name`); // (defaults to null)
if (username !== null) {
// Save for each setting
db.set(`users.${i}.name`, null);
db.set(`username${i}`, username);
}
}
db.set('dataVersion', 7);
console.log('Updated database to data version 7.');
}
/**
* Same thing but more performant (fewer writes to disk):
*/
if (dataVersion < 7) {
// Save backup file to './data.json.bak'
db.save(db.path + '.bak');
for (let i = 0; i < userCount; i++) {
let username = db.get(`users.${i}.name`); // (defaults to null)
if (username !== null) {
// Set values without saving
db.set(`users.${i}.name`, null, false);
db.set(`username${i}`, username, false);
}
}
// Save database file
db.save();
// Saves here as well (above save is redundant)
db.set('dataVersion', 7);
console.log('Updated database to data version 7.');
}
Note that I/O errors thrown by the fs-module are not caught and must be caught by the user of this module. The affected methods are Database.save, Database.set (unless called with save parameter set to false), and Database.constructor.
FAQs
A super lightweight synchronous database/settings module for local storage of key-value data.
We found that @tusent.io/json-database 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.

Company News
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.

Research
/Security News
Socket is tracking cloned Open VSX extensions tied to GlassWorm, with several updated from benign-looking sleepers into malware delivery vehicles.

Product
Reachability analysis for PHP is now available in experimental, helping teams identify which vulnerabilities are actually exploitable.