Server-Side API
NukeBase is a managed service that provides instant provisioning and deployment. Your project structure includes:
- server/database.js: The core database engine
- server/data/: Your database directory (a tree of
data.jsonfiles joined by$splitmarkers — see Storage & Backups) - server/rules.js: Security rules configuration
- server/app.js: Your application configuration file
- public/: Frontend files (index.html, css, js, etc.)
- sys/deploy.js: Deploy program
- sys/config.json: Deployment configuration
- node_modules/: Dependencies (auto-generated)
- package.json: NPM package configuration
- package-lock.json: Dependency lock file
Setup and Initialization
Getting started with NukeBase is simple - provision your project through our managed service and start developing immediately.
Step 1: Create Your Project
Getting started is as simple as visiting a URL in your browser:
1. Visit: https://nukebase.com/createuser
2. Fill in your project details (username, project name)
3. Click "Provision & Download"
4. Your project zip will download automatically
Instant Deployment: Your project is automatically provisioned, deployed, and live at:
https://username-project.nukebase.com
No build steps, no server configuration - just download the zip and start coding!
Step 2: Local Development Setup
After provisioning, extract the downloaded zip file and set up your VS Code workspace:
# 1. Extract the downloaded project zip file
# Right-click the .zip file and select "Extract All"
# 2. Open VS Code
# File → Add Folder to Workspace → Select your extracted project folder
# 3. Open Terminal in VS Code
# Terminal → New Terminal → Select Folder As Directory
# 4. Install NukeBase CLI globally
npm install -g
# 5. Install NukeBase NPM Packages
npm install
# 6. Now you can use NukeBase commands:
nukebase push # Push local changes to live server
nukebase pull # Pull live server changes to local
NukeBase CLI Commands:
nukebase push- Upload your local changes to the live servernukebase pull- Download the latest changes from the live server
Changes are synced in real-time, allowing you to develop locally and deploy instantly.
Push or pull will instantly remove or add folder/files to server/client unless sys/config "exclude": ["sys", "server/data.json"]
Step 3: Start Developing
Your project structure is ready to use:
- /public: Edit your frontend files (HTML, CSS, JavaScript)
- /server/app.js: Configure backend logic, domains, and database triggers
- /server/rules.js: Define security rules for data access
- /server/data/: Your real-time database directory (auto-synced)
Hot Reload: Changes to your /public files are instantly reflected on your live site. Backend changes in /server/app.js are automatically deployed.
Basic Server Configuration Structure
Your server/app.js file uses a module export pattern that provides access to all NukeBase APIs:
module.exports = ({
addDbTrigger,
addCallable,
addConnectionTrigger,
get,
set,
update,
remove,
query,
generateRequestId,
data,
addDomain,
startDB,
checkAuth,
withBody,
hashToken
}) => {
const path = require("path");
const nukebase = addDomain({
authPath: ["users"],
host: "127.0.0.1", // optional - defaults to "127.0.0.1"
port: 3000 // optional - defaults to 3000
});
nukebase.app.serveStatic("/*", path.join(__dirname, "../public"),
(res, req) => { return true; }
);
startDB(nukebase);
}
Available Exports
Your app.js module receives the following functions and objects:
| Export | Description |
|---|---|
get, set, update, remove, query | Core data operations — see CRUD Operations |
addDomain | Create a domain with auth and server config |
startDB | Start the server (call once at the end) |
addDbTrigger | Register database triggers — see Database Triggers |
addCallable | Register callable functions — see Callable Functions |
addConnectionTrigger | Register connection triggers — see Connection Triggers |
generateRequestId | Generate a random hex string (crypto.randomBytes). Default 8 bytes (16 hex chars); pass a byte count for longer IDs |
data | Direct read-only reference to the in-memory database object — see CRUD Operations |
checkAuth | Authenticate a request and return the auth context. Called automatically by postWithBody; call manually in raw post handlers |
withBody | Body-parsing middleware wrapper. Wraps a (res, req) handler to parse the request body and populate req.body and req.admin. Used internally by postWithBody — useful if you need to attach body parsing to a custom HTTP method |
hashToken | SHA-256 hash a string and return the hex digest. Used internally for session token storage — useful in extensions or callables that need to store/verify tokens the same way the auth system does |