Anon

The Anon class allows you to run and manage an Anon client with various configuration options.

Constructor

constructor(options?: Partial<AnonConfig>)

Creates a new instance of the Anon class.

  • options (optional): Partial<AnonConfig> - An object containing partial configuration options for the Anon client.

AnonConfig Properties

  • displayLog: boolean - Whether to display logs. Default: false

  • useExecFile: boolean - Whether to use execFile instead of spawn. Default: false

  • socksPort: number - The SOCKS port to use. Default: 9050

  • orPort: number - The OR (Onion Routing) port to use. Default: 0

  • controlPort: number - The control port to use. Default: 9051

  • binaryPath: string | undefined - The path to the Anon binary. Default: undefined

Methods

getSOCKSPort(): number

Retrieves the SOCKS port number configured for the Anon instance.

Returns: The SOCKS port number.

getControlPort(): number

Retrieves the Control port number configured for the Anon instance.

Returns: The Control port number.

getORPort(): number

Retrieves the OR (Onion Routing) port number configured for the Anon instance.

Returns: The OR port number.

async start(): Promise<void>

Starts the Anon client with the options configured in the constructor.

Throws: An error if the Anon process is already started.

async stop(): Promise<void>

Stops the Anon client.

isRunning(): boolean

Checks if the Anon client is currently running.

Returns: true if Anon is running, false otherwise.

Usage Example

javascriptCopyimport { Anon } from 'your-package-name';

const anonClient = new Anon({
  displayLog: true,
  socksPort: 9060
});

await anonClient.start();
console.log(`SOCKS Port: ${anonClient.getSOCKSPort()}`);
console.log(`Control Port: ${anonClient.getControlPort()}`);
console.log(`OR Port: ${anonClient.getORPort()}`);

// ... use the Anon client ...

if (anonClient.isRunning()) {
  await anonClient.stop();
}

Last updated