1 | socks-proxy-agent
|
2 | ================
|
3 | ### A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS
|
4 |
|
5 | This module provides an `http.Agent` implementation that connects to a
|
6 | specified SOCKS proxy server, and can be used with the built-in `http`
|
7 | and `https` modules.
|
8 |
|
9 | It can also be used in conjunction with the `ws` module to establish a WebSocket
|
10 | connection over a SOCKS proxy. See the "Examples" section below.
|
11 |
|
12 | Examples
|
13 | --------
|
14 |
|
15 | ```ts
|
16 | import https from 'https';
|
17 | import { SocksProxyAgent } from 'socks-proxy-agent';
|
18 |
|
19 | const agent = new SocksProxyAgent(
|
20 | 'socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com'
|
21 | );
|
22 |
|
23 | https.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
|
32 | import WebSocket from 'ws';
|
33 | import { SocksProxyAgent } from 'socks-proxy-agent';
|
34 |
|
35 | const agent = new SocksProxyAgent(
|
36 | 'socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com'
|
37 | );
|
38 |
|
39 | var socket = new WebSocket('ws://echo.websocket.events', { agent });
|
40 |
|
41 | socket.on('open', function () {
|
42 | console.log('"open" event!');
|
43 | socket.send('hello world');
|
44 | });
|
45 |
|
46 | socket.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 |