Appearance
What is MARS Engine?
MARS Engine is a server‑side JavaScript runtime and hosting platform purpose‑built for APIs, WebSockets, and document generation.
It lets you ship complete back‑end logic-from SQL queries to PDF reports-in a single, version‑controlled workspace that runs entirely in the browser and deploys with one click.
Core Ideas
Single‑function philosophy One universal helper per concern (param(), write(), db.query(), session(), …). Less syntax to memorise, more focus on business logic.
Transaction‑scoped execution Every request runs inside a database transaction. Succeed → auto‑commit; throw or exit → automatic rollback. Data integrity by default.
Built‑in realtime Define a WebSocket script alongside your API files and share the same helpers, sessions, and DB access-no extra infrastructure.
All‑in‑browser development Code editor, integrated database, environment settings, and deployment pipeline live in the same web UI. Nothing to install.
Building Blocks
API Scripts
Handle REST‑style or RPC endpoints.
js
// /api/echo.js
const defaultValue = 'Hello from MARS Engine!'
const message = param('msg', defaultValue);
write('echo', message);- Automatic JSON response
- Access to
db,fs,net,mail, and dozens of helpers - Runs in a transaction until the last line completes
WebSocket Scripts
Real‑time channels without boilerplate.
js
// onConnect
write('hello', 'Socket connected');
// onMessage
const data = param("data");
write('youSent', data);- Same helpers as API scripts
setId()to group sockets;disconnect()to kick clients
Libraries & Init Scripts
Share code or set globals.
js
// /lib/hash.js
exports.sha256 = str => sha(str, 256);
// /init/env.js (runs once at boot)
shared.VERSION = getConfig('app.version', 'dev');Reporting Engine
Generate PDF, ODT, XLSX, CSV from template files with one line:
js
const invoice = report.pdf('tpl/invoice.odt', { order });
write('file', invoice.data); // streams the PDFTypical Request Lifecycle
Client → MARS Engine
① open transaction
② run script
③ commit / rollback
④ assemble response
← Client- Input via
param()(URL, body, files) - Logic & Helpers-DB queries, HTTP calls, file ops, etc.
- Output with
write()(JSON) or by streaming a file buffer - Headers / status set anytime before the first
write()
Why Teams Choose MARS Engine
- Speed of development – boilerplate‑free helpers and an all‑browser IDE cut setup to minutes.
- Safety by design – default transactions, sanitisation helpers, and bcrypt utilities keep data consistent and secure.
- Full‑stack in one repo – APIs, realtime channels, scheduled jobs, and report templates live together, versioned and reviewable.
- Instant environments – dev, test, and live stages share configuration but isolate data, so promoting changes is a toggle, not a rebuild.
Learn More
- Quickstart: 5‑Minute Echo API
- Request Lifecycle Deep Dive
- API Reference → Such as: Params, Write, Firebase cloud messaging