Documentation
Welcome to the Baxxon documentation. Baxxon is a minimalist, structural web framework for Node.js designed to be learned in minutes, not days.
Getting Started
Installation
Baxxon is available via npm. Create a new directory and install it to begin.
mkdir my-app && cd my-app
npm init -y
npm install baxxon
Interactive Setup
Upon installation, Baxxon will ask if you want to automatically create a sites/ directory with a "Hello World" example. This is the fastest way to see the framework in action.
Core Concepts
The Visual Contract
Baxxon eliminates routing ambiguity by splitting the web into two mutually exclusive categories based on the URL structure:
- Physical Assets (Static): If the URL contains a dot (e.g.,
/images/logo.png,/style.css), Baxxon serves the file directly from thepublic/directory. - Dynamic Logic (JS Modules): If the URL has no dot (e.g.,
/about,/api/data), Baxxon routes the request to themodules/directory.
Dynamic Logic via JS Modules
Baxxon believes in "No Magic." Your dynamic routes are handled by standard Node.js JS Modules. Each module exports a default function that receives the bx controller.
// modules/index.js
export default function(bx) {
bx.render.HTML('<h1>Hello World</h1>');
}
The Slash-Param Engine
Baxxon uses a deterministic parser that treats trailing URL segments as data. No complex regex or routing tables are required.
// Example URL: /products/category/shoes/sort/price
// Access as Key/Value pairs (unpaired segments default to '1')
bx.reqURL.searchParams.get('category') // "shoes"
bx.reqURL.searchParams.get('sort') // "price"
// Access as a raw positional array
bx.params[1] // "shoes"
The bx Controller API
The bx object is your primary interface to the framework's features.
Properties
bx.params: Array of trailing URL segments found after the module path.bx.server.req.body: The parsed body of a POST request (JSON or Form).bx.host: The request hostname.bx.paths.site: The absolute path to the current site directory.
Rendering Methods
Methods to terminate a request and deliver content:
bx.render.HTML(string): Renders an HTML response.bx.render.JSON(object): Renders a JSON response.bx.render.TEXT(string): Renders plain text.bx.render.MARKDOWN(string): Converts Markdown to HTML and renders it.bx.render.FILE(path): Streams a static file from thepublic/directory.
Built-in Tools
TextDB (Filesystem Database)
Baxxon includes TextDB, a minimalist flat-file database where folders are tables and .txt files are records.
import TextDB from 'baxxon/textdb';
const db = new TextDB({
rootPath: './data',
dirs: ['users']
});
await db.setData(); // Loads all data from the filesystem
const users = db.getData();
Consistent API Logic
In Baxxon, an API is simply a JS module that returns JSON. The framework uses the same logic and directory structure for APIs as it does for HTML pages, ensuring a unified development experience.