UNPKG

1.26 kBMarkdownView Raw
1socks-proxy-agent
2================
3### A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS
4
5This module provides an `http.Agent` implementation that connects to a
6specified SOCKS proxy server, and can be used with the built-in `http`
7and `https` modules.
8
9It can also be used in conjunction with the `ws` module to establish a WebSocket
10connection over a SOCKS proxy. See the "Examples" section below.
11
12Examples
13--------
14
15```ts
16import https from 'https';
17import { SocksProxyAgent } from 'socks-proxy-agent';
18
19const agent = new SocksProxyAgent(
20 'socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com'
21);
22
23https.get('https://ipinfo.io', { agent }, (res) => {
24 console.log(res.headers);
25 res.pipe(process.stdout);
26});
27```
28
29#### `ws` WebSocket connection example
30
31```ts
32import WebSocket from 'ws';
33import { SocksProxyAgent } from 'socks-proxy-agent';
34
35const agent = new SocksProxyAgent(
36 'socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com'
37);
38
39var socket = new WebSocket('ws://echo.websocket.events', { agent });
40
41socket.on('open', function () {
42 console.log('"open" event!');
43 socket.send('hello world');
44});
45
46socket.on('message', function (data, flags) {
47 console.log('"message" event! %j %j', data, flags);
48 socket.close();
49});
50```
\No newline at end of file