@37o1/httpdb
v1.1.0-stable
Published
TypeScript/JavaScript http based database
Downloads
21
Readme
HttpDB
An extension to LW-DB that adds query and lan use
HttpDB is a wrapper module for lw-db that allows multiple nodejs processes and compatible apps to access one database without the need of process synchronization. It also allows multiple computers to access the same database, however I do not advise doing that.
Setup
ES5
const { dbserver, dbclient } = require("httpdb");
const server = new dbserver("path/to/db/folder", true); // set up the database server
const client = new dbclient(server.accessToken); // use client to access the database
ES6
import { dbserver, dbclient } from "httpdb";
const server = new dbserver("path/to/db/folder", true);
const client = new dbclient(server.accessToken);
You can define the client in any process or computer you wish.
In order to access a remote database you need to be able to establish a TCP connection between the two machines. Setting up a local database for multiple machines is fine if you trust the devices and their users. You can set up muliple databases for multiple users if you want to set up granular access control.
If you want to extend security I advise you to do somthing like the following:
const server = require("http").createServer();
const dbserver = new require("httpdb").dbserver("path/to/db/folder", false);
server.on("request", (req, res) => {
var passed = false;
// here you canb implement your own security/access-control system
// set passed to true is security checks passed
if (passed) dbserver.handle(req, res);
});
Notes
This module purely uses headers for client to server transmit Make sure to set the max header size to a high value if you expect the client(s) to write a lot of data to a single file
Reserved headers
token
: accessToken
action
: action flag
data
: strigified JSON data
lw-db
The underlying module of httpdb is lw-db, a node:fs wrapper module! This module is a pure JSON database that works locally and does not ecrypt data. Make sure to implement your own data encryption medthod.
Disclaimers
This module DOES NOT ENCRYPT DATA! Not in transmit and neither when saving. This module DOES NOT BACK UP!
THIS MODULE IS IN ACTIVE DEVELOPMENT! I AM NOT LIABLE IN ANY WAY FOR ANY OR FORM FOR ANY DATA LEAK OR DATA LOSS!