Node.js API
Engine Lifecycle
Start, stop, and manage the Risuko engine in Node.js.
startEngine
Initialize and start the download engine. Must be called before any other API function.
function startEngine(config?: EngineConfig): Promise<void>;EngineConfig
interface EngineConfig {
/** Custom config directory. Default: OS config dir / dev.risuko.app */
configDir?: string;
/** RPC listen port. Default: 16800 */
rpcPort?: number;
/** Whether to start the RPC server. Default: true */
enableRpc?: boolean;
}Examples
import { startEngine } from "@risuko/risuko-js";
// Use defaults
await startEngine();
// Custom configuration
await startEngine({
configDir: "/path/to/config",
rpcPort: 6800,
enableRpc: true,
});Only one engine instance can run per process. Calling startEngine when the engine is already running throws an error.
What Happens on Start
- The config directory is created (if it doesn't exist)
system.jsonanduser.jsonconfig files are loaded (or defaults created)- The download directory is created
- The task manager is initialized
- Session is restored (previously active downloads resume)
- The RPC server is started (if
enableRpcis true) - Event broadcasting and auto-save tasks begin
stopEngine
Gracefully shut down the engine. Saves the current session and stops all running tasks.
function stopEngine(): Promise<void>;import { stopEngine } from "@risuko/risuko-js";
await stopEngine();Session Management
saveSession
Persist the current download session to disk. The session is also auto-saved periodically.
function saveSession(): Promise<void>;purgeDownloadResult
Remove all completed, errored, and removed download results from memory.
function purgeDownloadResult(): Promise<void>;removeDownloadResult
Remove a specific download result by GID.
function removeDownloadResult(gid: string): Promise<void>;Example
import { saveSession, purgeDownloadResult } from "@risuko/risuko-js";
// Force save
await saveSession();
// Clean up finished downloads
await purgeDownloadResult();