Introduction
Terminology, directory structure, and supported runtime
All examples in this chapter utilize Node.js. If you prefer Bun, substitute node with bun in the commands.
Terminology
Before proceeding, familiarize yourself with these terminologies used throughout this documentation:
{appDir}: The application’s project directory where all your code residese.{dataDir}: The directory for all data; defaults to{appDir}/dataand is created automatically if missing.{tmpDir}: The temporary directory, defaults to the OS temporary directory.{pkgName}: The plugin’s package name, typically matching its npm listing.{ns}: The plugin name or namespace, which is the camel-cased version of the package name.{mainNs}: The special main namespace and directory named main within your{appDir}; this is where all application code should be written.
Directory Structure
Your typical Bajo app directory structure should look like this:
.
└── {appDir}
├── {dataDir}
│ ├── config
│ │ ├── .plugin
│ │ ├── bajo.json
│ │ ├── main.json
│ │ └── ...
│ └── plugins
│ └── ...
├── main
│ ├── extend
│ │ └── ...
│ ├── index.js
│ └── ...
├── package.json
├── index.js
└── ...
- You can move
{dataDir}out of{appDir}if you want, but you need to tell Bajo where to find it. For more on this, please follow along. {dataDir}should be the only place Bajo writes anything. Bajo and its plugins should never be allowed to write anything outside{dataDir}on their own.configis a special directory within{dataDir}where your configuration files should reside. Inside this directory, you should find:- a special file named
.pluginsthat tells Bajo which plugins should be loaded - a file named
bajo.jsonto configure global settings - all plugin-specific config files, named after their namespace
- a special file named
- The
maindirectory, or{mainNs}namespace, is the special plugin where you put your application code. And yes, it is actually a normal Bajo plugin! This means everything in there will be handled just like a regular plugin—it has the ability to extend other plugins, has its own config file, and more — with a few differences:- it’s always available and can’t be disabled
- it’s always the last one to start
- if this directory is missing, it will be created automatically on startup
- if the plugin’s factory function is missing (
index.js), it will be created dynamically
index.jsis the main entry point for your app.
To set your {dataDir} somewhere else, you need to tell Bajo where to find it by using an argument switch.
Assuming your data directory is my-data-dir at the same level as your app directory, run your app like this:
$ node index.js --dir-data=../my-data-dir
If using program arguments seems a bit like a hassle for you, just use Bajo’s dotenv support. Create a .env file in your app directory and put this inside:
DIR__DATA=../my-data-dir # double underscores!!!
From now on, you can start the app just by typing:
$ node index.js
Runtime
Bajo should run perfectly fine on Node.js version 20 or higher. Using the latest stable runtime is recommended. Bajo-based apps are also known to run with Bun without any problems. But Bajo cannot run on Deno due to its heavy reliance on Node.js-specific libraries and environments.
Bajo is a pure ES6 framework that utilizes dynamic imports a lot. Running on a system with a fast disk (e.g., SSD) and enough RAM is highly recommended, especially when you load a lot of plugins.