Skip to content

Server Setup

import {
class DatabaseServer<T extends string[]>

Database Server

DatabaseServer
} from "@vimn/webdb"
new
new DatabaseServer<string[]>(config: ServerConfig<string[]>): DatabaseServer<string[]>

Database Server

DatabaseServer
({
ServerConfig<T extends string[]>.auth: string

Authentication key for requests. I recommend using secure keys, e.g. UUID

auth
:
const AUTH_KEY: string

This must be a unique secret string, use env variables

AUTH_KEY
,
ServerConfig<T extends string[]>.host: string

Host to use

host
: '0.0.0.0',
ServerConfig<T extends string[]>.port: number

Port to use

port
: 80,
ServerConfig<string[]>.tables: string[]

Database tables

tables
: ["main", "users", "guilds"],
ServerConfig<T extends string[]>.safe: boolean

Disables actions that could be risky. Ex: Delete an entire table or delete several tables.

safe
: true,
ServerConfig<T extends string[]>.path: string

Path to save all data

path
: './db'
}).
DatabaseServer<string[]>.begin(): Promise<void>

Starts the database

begin
();

The code seen here starts the express server and creates the necessary files, I will explain each part of the configuration below:

Explanation of the configuration

  1. Auth:

    This is the authentication key, it is used to verify that the request is valid.

  2. Host:

    This is the host that the server will listen to.

  3. Port:

    This is the port that the server will listen to.

  4. Tables:

    These are the tables that the server will create, you can create as many as you want.

  5. Safe:

    This is a boolean that if it is true, disables actions that could be risky. Ex: Delete or overwrite an entire table.

  6. Path:

    This is the path where the tables will be created.