Client-Side API
NukeBase's client library provides a real-time connection to your database through WebSockets. The client handles connection management, request tracking, and event dispatching automatically.
Looking for get/set/update/increment/remove/query? Those work the same on client and server and are documented once in CRUD Operations and Query Operations. The client returns Promises (use await); otherwise the API is identical.
Everything createClient() returns
| Method | Does |
|---|---|
| Data — see CRUD Operations | |
get(path) | Read the value at a path |
set(path, data, opts?) | Create or replace. opts.durable waits for the disk flush |
update(path, data, opts?) | Deep-merge into the existing value |
increment(path, data, opts?) | Apply a numeric delta, or a nested object of deltas, atomically. Resolves with the resulting value(s) |
remove(path, opts?) | Delete the value at a path |
query(msg) | Search a collection. Takes childPath, orderBy, desc, limit, startAt, cursor, count — see Sorting and Pagination |
| Subscriptions — see Real-time Subscriptions. Each returns an unsubscribe function | |
getSub({event, path}, fn) | Live value at a path |
getSubChanged({event, path}, fn) | Same, but deltas after the first payload |
querySub({…}, fn) | Live query result, optionally windowed with orderBy/limit |
querySubChanged({…}, fn) | Same, but only the records each write touched |
| Files — see File Storage | |
getFile(path, opts?) | Download. Resolves with a Blob |
setFile(path, body, opts?) | Upload a Blob, File, ArrayBuffer, TypedArray or string |
listFiles(path, opts?) | One directory level as an array of entries |
removeFile(path, opts?) | Delete; directories need { recursive: true } |
fileUrl(path) | Synchronous. The URL for <img src> or <a href> — rules still apply when the browser fetches it |
| Server functions and auth | |
callableFunction(name, data) | Invoke a server callable — see Calling Callables |
login(username, password) | Sign in, or resume a cookie session with no arguments |
logout() | Clear cookies and revoke the session token |
createUser(username, password) | Create an account. Its endpoint ships commented out — accounts are created by the email flows instead, so this 404s unless you re-enable /createuser |
changePassword(newPassword) | Change the signed-in user's password |
magicLink(email) | Request a passwordless sign-in link |
reconnect() | Tear down and re-open the socket. Called automatically after a successful login/logout so the new cookies are picked up |
Two different error conventions, on purpose. Data methods, subscriptions and callables resolve with { status: "Failed" } — they never reject on a refusal, so you must check status. The four file methods reject with a NukeBaseFileError carrying the HTTP .status, because a file transfer's failure modes (403, 404, 409, 413, 429) are exactly what you want to branch on. See Response Format.
Auth methods depend on extensions being mounted. login and changePassword need extensions/auth on the server; magicLink needs extensions/magic-link; createUser additionally needs its route uncommented. Only logout is backed by the core engine. A method whose endpoint isn't routed falls through to the static handler and gets a 404, which surfaces as a JSON parse error rather than a clear message. See Authentication.