https://github.com/shahradelahi/node-tor-control
A NodeJs library to communicate with Tor-Control
https://github.com/shahradelahi/node-tor-control
javascript nodejs tor
Last synced: about 1 year ago
JSON representation
A NodeJs library to communicate with Tor-Control
- Host: GitHub
- URL: https://github.com/shahradelahi/node-tor-control
- Owner: shahradelahi
- License: gpl-3.0
- Created: 2024-03-01T00:41:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-29T04:02:15.000Z (about 1 year ago)
- Last Synced: 2025-04-01T22:55:39.090Z (about 1 year ago)
- Topics: javascript, nodejs, tor
- Language: TypeScript
- Homepage: https://npmjs.com/tor-ctrl
- Size: 156 KB
- Stars: 77
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tor-ctrl
[](https://github.com/shahradelahi/node-tor-control/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/tor-ctrl)
[](https://packagephobia.com/result?p=tor-ctrl)
[](/LICENSE)
_tor-ctrl_ is a simple library to connect to a Tor control port and send commands to it.
## 📦 Installation
```bash
npm install tor-ctrl
```
## 📖 Usage
In below example, we are requesting for a new identity from Tor.
```typescript
import { TorControl } from 'tor-ctrl';
const tc = new TorControl({
host: 'localhost',
port: 9051,
// Or, if you want to control via Tor Unix socket:
// socketPath: '/var/run/tor/control',
password: 'secure-password'
});
await tc.connect();
const { data } = await tc.getNewIdentity();
console.log(data); // { code: 250, message: 'OK' }
await tc.disconnect();
```
###### Send a Custom Command
If you don't know the available commands, please first check out the official the [Tor Control Protocol](https://spec.torproject.org/control-spec/commands.html) specifications.
```typescript
const { data, error } = await tc.sendCommand(['GETINFO', 'version', 'config-file']);
console.log(data); // [ { code: NUM, message: STRING }, ... ]
```
For more examples, check out the [examples](/examples) directory.
## 🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/node-tor-control).
Thanks again for your support, it is much appreciated! 🙏
## License
[GPL-3.0](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/node-tor-control/graphs/contributors).