A not so baisc json database system for Node.js including a method for Encryption, and a system for a Remote Database using a simple key and value pair system with an easy to use functionality for the end user and developer
Developed By MrShoe_
VERSION: v3.1.4
use this command to install
npm install elementary-dbTo setup use the following
const Database = require('elementary-db');
const db = new Database('database');Or you can do this
const Database = require('elementary-db');
const db = Database.init('database');And note use this to init a database that suports old files
const Database = require('elementary-db');
const db = new Database('database', {
"useOld": true
});To set any config use the .configure function
Set autosave to false use this command
db.configure('autosave', false)- AutoSave
- Save a project to disk after evey change
- Value Type: True/False
- Default Value: True
- Setting value: 'autosave'
- DontSave
- Disable The ability to save to the drive, only load a file but dont save to it
- Value Type: True/False
- Default Value: False
- Setting value: 'dontsave'
Info about data encryption is found at line 163
db.getConfig("Config-Value")NOTE: More configuration will be avalible in a latter update! Check back soon!
to grab data use the .get function
db.get(key)Use .set to set data
db.set(key, value)To delete data use .del
db.del(key)To grab the keys use this
db.keys()To check if a key use .has
db.has(key)To save the data to the json source use .save
db.save()NOTE: You don't need to use this command unless you set 'autosave' to false
To get all data use .getAll
db.getAll()To setall data use .setAll
db.setAll(newJsonData)use this function to convert a .json file to the newest version of an .edb version
Database.convertToNew('file.json')then in your database just input the name, "file"
Unfortunetly We are no longer suporting the array database format, sorry for the inconvenionce to those using this format, we have provided a aternative method for similar results bellow this message
const Backup = new Database('database')
if (Backup.has('data')) {
const array = Backup.get('data')
} else {
Backup.set('data', [])
const array = Backup.get('data')
}Again, sorry for the inconvenience.
To inetalise a encrypted database use this using this to setup the database object
const Database = require('elementary-db');
const db = new Database('database', {
"encrypted": true,
"encryptedKey": 'encryption key'
});Then the database will work like normal, now the database just has an extra layer of protection
And as a side note, we HIGHLY recomend you turn off autosave if you have this enabled, it is on by default but the automatic saving to the disk can slow down other processes
The key MUST be at least 256 bits long or 32 charicters long as a minimum, but if you are very worryed about your user data and or procecsing time, we would recomend you encrypt and decrypt your own private data or use both for an extra player of protection
Example code: ;wch)xTdO0!@Ccv6mxwC8r3cyJmvV-x}
Codes can also not contain the charicter "" or "/"
IMPORTANT NOTICE: The remote feture is a beta feture and is still in development, so some parts may be broken and not work on ocations, to report any bugs, got to the github isuse tab, HERE or send an email to mrshoeshoe66@gmail.com
Here is how to create a connection to a server
const Database = require('elementary-db')
const server = new Database.remote('<SERVER-IP>', { Settings })Then after that the database works almost the same, the only change is that all the all the functions are now asynchronous and will have a small delay in the value return as it needs to return a promies object to allow time for the request to be sent to the server
The settingns is used to dictate if the server is secured or not
Example:
const Database = require('elementary-db')
const server = new Database.remote('<SERVER-IP>', { secure: true })And as a note, it's considered secured here when its through https trafic instead of http trafic, and it can either be secured through the package itself or through another routeing softwhere! Just thought I should clarify
- secure
- Is the server run with https?
- Values:
- true/false
- password
- Password for database
- Simple text value
Creating a server is the easy part, here is how you do it
const Database = require('elementary-db')
const server = new Database.remote.server({ settings })And to start the server simply use this command
server.start()But make sure to initiate the server with this first
server.createServer()After the server starts an output similar to this
elementary-db database server running at ip of: 127.0.0.1and the ip is used to connect to the server from the client
Currently, the only availible setting is a password, herw is how yout set it up
const server = new Database.remote.server({
password: 'Password'
})I would recomend forwarding it through Nginx, but if you would rather do it through the package, use this instead:
server.createServerSecure( keyfilepath, certfilepath )where to 2 inputs are the path to the certifacate files
If there is an error, details wil apear in the edblogs.txt file, client and server side
but on the server if anything happens, like a connection from a client or an error, it will also show up in the edblogs.txt file with timestamps of when it happened