Simple JSON "database" for NodeJS.
All files will be stored in the NyaDB
folder in the project's root directory.
This package requires Node.js version 12.x or higher for compatibility with the features and syntax used in the codebase.
npm install @decaded/nyadb
const NyaDB = require('@decaded/nyadb');
const nyadb = new NyaDB();
You can pass settings on initialization. More information below.
nyadb.create('test'); // Creates a new database called 'test'
const mockDatabase = {
yellow: ['banana', 'citrus'],
red: ['apple', 'paprika'],
};
nyadb.set('test', mockDatabase); // Sets the database 'test' to the 'mockDatabase' object
nyadb.get('test'); // Returns the 'test' database
// {
// "yellow": ["banana", "citrus"],
// "red": ["apple", "paprika"],
// }
nyadb.getList(); // Returns the names of all databases in an array
// ['test']
nyadb.delete('test'); // Deletes the database 'test'
You can customize the behavior of the application by modifying the following settings.
Setting | Default Value | Optional Values | Description |
---|---|---|---|
formattingEnabled | true | false | Enable or disable formatting of output. |
formattingStyle | tab | space | Choose between using tabs or spaces for indentation. |
indentSize | 4 | Any non-negative integer | Specify the number of spaces for indentation. Only applicable if formattingStyle is set to "space". |
encoding | utf8 | Any valid encoding supported by Node.js | Specify the encoding for file input/output operations. |
enableConsoleLogs | false | true | Enable or disable logging output to the console. Errors will be logged regardless of this setting. |
const nyadb = new NyaDB({ formattingStyle: 'space', indentSize: 5 });
- Changes to these settings will take effect immediately on initialization.
- To return to the default values, simply remove the setting.
NyaDB version 3 is fully compatible with databases created using version 2.x. and 1.x. No data migration is required when upgrading to version 3.
⚠ NyaDB version 3 introduces strict procedures for handling configuration settings. If you use them, make sure you pass the correct values listed in the table.
⚠ If you are migrating from 1.x, make sure to update your methods as listed below.
In version 2.0, some method names were updated for consistency and clarity. Here’s a quick guide on how to update your code:
createDatabase()
is nowcreate()
deleteDatabase()
is nowdelete()
setDatabase()
is nowset()
getDatabase()
is nowget()
getDatabaseList()
is nowgetList()
For example, if you previously used nyadb.createDatabase('test')
, you should now use nyadb.create('test')
.
Passing arguments on initialization is optional and compatible with version 1.x and 2.x, meaning if you initialized it like this:
const NyaDB = require('@decaded/nyadb');
const nyadb = new NyaDB();
It will still work in version 3.0 the same way as it did before. Just make sure you updated your methods as shown above if you are migrating from version 1.x.
Please note that the previous method names have been deprecated since version 1.5.0 and were removed in 2.0.
This project is licensed under the MIT License. See the LICENSE file for details.
If you find this project helpful or fun to use, consider supporting me on Ko-fi! Your support helps me keep creating and improving.