Create Database
AxioDB constructor follows the pattern: new AxioDB(options) where options is an object with {HTTP?, RootName?, CustomPath?, TCP?, TCPAuth?, AdminPassword?, TLS?, TLSCertPath?, TLSKeyPath?, Cache?, minTTL?, maxTTL?, cacheClearUp?}. This pattern provides better readability and flexibility.
💡 Constructor Parameters
- HTTP (boolean, optional): Enable HTTP REST API server on port 27018 - defaults to false
- RootName (string, optional): Custom root folder name - defaults to "AxioDB"
- CustomPath (string, optional): Custom storage path - defaults to current directory
- TCP (boolean, optional): Enable the AxioDBCloud TCP server on port 27019 - defaults to false
- TCPAuth (boolean, optional): Require username/password authentication (same RBAC users as HTTP API) on TCP connections - defaults to true when TCP is enabled (set to false to disable)
- AdminPassword (string, optional): Password the admin account is seeded with on first start, skipping the forced first-login change - defaults to the built-in admin/admin
- TLS (boolean, optional): Encrypt the TCP server with TLS - requires TLSCertPath + TLSKeyPath PEM files - defaults to false
- Cache (boolean, optional): Enable the per-instance InMemoryCache - defaults to true (set false to disable caching entirely)
- minTTL (number, optional): Minimum randomized cache TTL in minutes - defaults to 5
- maxTTL (number, optional): Maximum randomized cache TTL in minutes - defaults to 15
- cacheClearUp (number, optional): Cache cleanup sweep interval in seconds - defaults to 86400
Setting the Admin Password (Headless Mode)
On first start AxioDB seeds an admin/admin account and flags it mustChangePassword: true. The forced change can only be completed through the HTTP API - so if you start the server with HTTP: false and TCPAuth: true, there would be no way to choose a password and TCP would reject every login. Pass AdminPassword to seed the account ready to use instead.
1const db = new AxioDB({2 TCP: true,3 TCPAuth: true,4 AdminPassword: 'my-secret-password',5});6
7// admin / my-secret-password can log in over TCP immediately- One account, every surface. Embedded, HTTP, GUI, TCP and MCP all read the same
configdatabase, so this password is the same everywhere. - First start only. The value is read solely when the
userscollection is created. Once your data directory exists, restarting never resets a password you have since changed. - Opt-in. Omit it and the default
admin/admin+ forced change behaviour is exactly as before - no breaking change. - Same option in the CLI and Docker.
axiodb serve tcp-auth <password>and theAXIODB_ADMIN_PASSWORDenvironment variable both map to it.
Quick Boilerplate (Embedded Mode)
Quick start with zero configuration — runs in embedded mode with sub-millisecond in-memory caching and ACID disk persistence.
1
2const { AxioDB } = require("axiodb");3
4// Quick boilerplate - create AxioDB instance in embedded mode5const db = new AxioDB();6console.log("AxioDB instance created in embedded mode");Instance with HTTP REST API
Enable the HTTP REST API server on port 27018 for remote clients or management tools.
1
2// Create AxioDB instance with HTTP REST API enabled3const db = new AxioDB({ HTTP: true });4console.log("AxioDB instance created with HTTP REST API at localhost:27018");Custom Database Name
Specify a custom root folder name for your database.
1
2// Create AxioDB instance with HTTP API and custom root folder name3const db = new AxioDB({ HTTP: true, RootName: "MyCustomDB" });4console.log("Custom AxioDB instance created with HTTP API");Custom Storage Path
Store database files in a specific directory.
1
2// Create AxioDB instance with HTTP API, custom name, and custom path3const db = new AxioDB({ HTTP: true, RootName: "MyCustomDB", CustomPath: "./data" });4console.log("AxioDB instance with custom path created");TCP Server with Authentication
Enable remote access via AxioDBCloud and require login before any TCP command is accepted.
1
2// Create AxioDB instance with the TCP server enabled and authentication required3const db = new AxioDB({ TCP: true, TCPAuth: true, RootName: "MyCustomDB", CustomPath: "./data" });4console.log("AxioDB instance with authenticated TCP access created");Cache Tuning
Each instance owns an InMemoryCache. Tune its randomized TTL bounds and cleanup interval, or disable it entirely with Cache: false.
1
2// Tune the per-instance InMemoryCache: 10-30 minute randomized TTL, hourly cleanup3const db = new AxioDB({ Cache: true, minTTL: 10, maxTTL: 30, cacheClearUp: 3600 });4
5// Disable caching entirely (reads always hit disk)6const dbNoCache = new AxioDB({ Cache: false });Create Multiple Databases
Create multiple isolated databases within your AxioDB instance.
1
2// Create databases under the current AxioDB instance3const userDB = await db.createDB("UsersDB");4console.log("Database 'UsersDB' created");5
6const productsDB = await db.createDB("ProductsDB");7console.log("Database 'ProductsDB' created");⚠️ Important Notes
- Only one AxioDB instance is allowed per application (singleton pattern)
- HTTP REST API runs on localhost:27018 and starts automatically when enabled
- Database files are stored in the root folder you specify
- Each database can contain multiple collections
See also: Create Collection · Usage
