Risuko
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 rejects with an Engine already running error.

What Happens on Start

  1. The config directory is created (if it doesn't exist)
  2. system.json and user.json config files are loaded (or defaults created)
  3. The download directory is created
  4. The task manager is initialized
  5. Session is restored (torrents resume automatically; other previously active downloads are restored as paused)
  6. The RPC server is started (if enableRpc is true)
  7. Background tasks begin: progress updates every second, session auto-save every 30 seconds

stopEngine

Gracefully shut down the engine. Cancels all running downloads, saves the current session, and stops the RPC server and background tasks. Rejects with Engine not running if the engine is not started — as does every other API function.

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 every 30 seconds.

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. Rejects if the GID is unknown or the download is not stopped. Files on disk are kept.

function removeDownloadResult(gid: string): Promise<void>;

Example

import { saveSession, purgeDownloadResult } from "@risuko/risuko-js";

// Force save
await saveSession();

// Clean up finished downloads
await purgeDownloadResult();

On this page