A lightweight Node.js library for managing key-value properties in a file-based database. It supports parsing, retrieving, updating, and deleting properties while preserving comments and formatting.
- File-Based Storage: Uses a
.propertiesfile for storing key-value pairs. - Supports Multiple Data Types: Handles strings, numbers, and booleans.
- Comment Preservation: Keeps comments intact when modifying the file.
- Simple API: Easy-to-use methods for managing properties.
npm install simple-properties-dbconst SimplePropertiesDB = require('simple-properties-db');const db = new SimplePropertiesDB('./config'); // Path to the directory where the file will be createdThis will create a db.properties file in the specified directory if it doesn't already exist.
db.set('username', 'johndoe');
db.set('age', 30);
db.set('isAdmin', true);const username = db.get('username'); // 'johndoe'
const age = db.get('age'); // 30
const isAdmin = db.get('isAdmin'); // trueconst allValues = db.getAll();
console.log(allValues);
// Output: { username: 'johndoe', age: 30, isAdmin: true }db.delete('username');
console.log(db.get('username')); // undefinedIf the .properties file contains comments, they will be preserved when modifying the file:
# This is a comment
username=johndoe
# Another comment
age=30dbPath: Path to the directory where the.propertiesfile will be stored. Defaults to the current working directory.options: (Optional) Additional configuration options.
Sets a key-value pair in the database.
key: The key to set.value: The value to associate with the key (string, number, or boolean).
Retrieves the value associated with a key.
key: The key to retrieve.
Retrieves all key-value pairs as an object.
Deletes a key-value pair from the database.
key: The key to delete.
# User configuration
username=johndoe
age=30
isAdmin=trueRun the tests using Jest:
npm testThis project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to open an issue or submit a pull request.
Developed by sjh.