# toragent

> Easily create and manage Tor requests

Latest version **0.1.1** (published 2016-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install toragent
pnpm add toragent
yarn add toragent
bun add toragent
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2016-10-06 |
| First published | 2015-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Daniel St. Jules |
| Maintainers | danielstjules |
| Keywords | tor, http, https, client, connection |

## Links

- npm: https://www.npmjs.com/package/toragent
- Repository: https://github.com/danielstjules/toragent
- Homepage: https://github.com/danielstjules/toragent#readme
- Issues: https://github.com/danielstjules/toragent/issues
- npm.io page: https://npm.io/package/toragent

## Dependencies (4)

- [tmp](https://npm.io/package/tmp.md) 0.0.27
- [bluebird](https://npm.io/package/bluebird.md) ^2.9.34
- [openports](https://npm.io/package/openports.md) 0.0.1
- [socks5-client](https://npm.io/package/socks5-client.md) 1.1.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2016-10-06
- 0.1.0 — 2015-08-18

## README

# toragent

Easily manage HTTP(S) requests through Tor. TorAgent spawns Tor processes,
handles both HTTP and HTTPS requests, and offers easy IP address rotation.
Compatible with `http.request` and libraries like `request`.

[![Build Status](https://travis-ci.org/danielstjules/toragent.svg?branch=master)](https://travis-ci.org/danielstjules/toragent)

## Installation

Requires Node >= 0.12 or iojs.

```
npm install --save toragent
```

## Overview

Works with promises.

``` javascript
var TorAgent = require('toragent');
var Promise  = require('bluebird');
var request  = Promise.promisify(require('request'));

function printGoogleHome() {
  return TorAgent.create().then(function(agent) {
    return request({
      url: 'https://www.google.com',
      agent: agent,
    });
  }).spread(function(res, body) {
    console.log(body);
  });
}
```

And callbacks too!

``` javascript
var TorAgent = require('toragent');
var request  = require('request');

function printGoogleHome(fn) {
  TorAgent.create(false, function(err, agent) {
    if (err) return fn(err);

    request({
      url: 'https://www.google.com',
      agent: agent,
    }, function(err, res, body) {
      if (err) return fn(err);

      console.log(body);
      fn();
    });
  });
}
```

## TorAgent

An HTTP Agent for proxying requests through Tor using SOCKS5. In the following
examples, `agent` refers to an instance of `TorAgent`.

#### TorAgent.create(verbose, [fn])

Spawns a Tor process listening on a random unused port, and creates an
agent for use with HTTP(S) requests. The optional verbose param will enable
console output while initializing Tor. Accepts an optional callback,
otherwise it returns a promise that resolves with an instance of TorAgent.
Note that since the Tor process is using a new DataDirectory with no cached
microdescriptors or any other state, bootstrapping can take between 15 - 60s.
The resulting child process is automatically killed when node exits.

``` javascript
TorAgent.create(true).then(function(agent) {
  // Spawning Tor
  // Tor spawned with pid 42776 listening on 55683
});
```

#### agent.rotateAddress()

Rotates the IP address used by Tor by sending a SIGHUP. Returns a promise
that resolves when complete.

``` javascript
TorAgent.create().then(function(agent) {
  return agent.rotateAddress();
});
```

#### agent.destroy()

Closes all sockets handled by the agent, and closes the Tor process. Returns
a promise that resolves when the Tor process has closed.

``` javascript
TorAgent.create().then(function(agent) {
  return agent.destroy();
});
```

---
_Source: https://npm.io/package/toragent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
