{"_id":"@derhuerst/socks-agent-with-socket-ttl","_rev":"1-91a7c63c78aa2edbca0a3efe3413b59d","name":"@derhuerst/socks-agent-with-socket-ttl","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@derhuerst/socks-agent-with-socket-ttl","description":"Node.js SOCKS5 Agent with a configurable sockets TTL.","version":"1.0.0","main":"index.js","keywords":["agent","proxy","socks","socks5","ttl"],"author":{"name":"Jannis R","email":"mail@jannisr.de"},"homepage":"https://github.com/derhuerst/socks-agent-with-socket-ttl","repository":{"type":"git","url":"git+https://github.com/derhuerst/socks-agent-with-socket-ttl.git"},"bugs":{"url":"https://github.com/derhuerst/socks-agent-with-socket-ttl/issues"},"license":"ISC","engines":{"node":">=16"},"dependencies":{"debug":"^4.3.3","socksv5":"github:Miovision/socksv5#71e8437"},"devDependencies":{"eslint":"^8.0.0","node-fetch":"^2.6.6"},"scripts":{"lint":"eslint .","prepublishOnly":"npm run lint"},"gitHead":"d96d4d945002a6d1aae5d69bef40f6532906f2ba","_id":"@derhuerst/socks-agent-with-socket-ttl@1.0.0","_nodeVersion":"17.0.1","_npmVersion":"8.1.3","dist":{"integrity":"sha512-rmuFH0bkIeAhmkUfYIm5EUiDFxr/Zg1B+ftm0S8e2arjdU3pfs8w4JsmkZr6yzadvsfZAemcspcVn9SgH9n8Vg==","shasum":"68fafd3da806d9e058e298c50d418308aa1ab73d","tarball":"https://registry.npmjs.org/@derhuerst/socks-agent-with-socket-ttl/-/socks-agent-with-socket-ttl-1.0.0.tgz","fileCount":5,"unpackedSize":6406,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhtSSTCRA9TVsSAnZWagAAjx0P/1zy9uAYCPURg+Wz3RLc\nAUGL3byokSkGdKY4OaUK6t77nJ4Eb2Rig6/RD//FtVbwHAJzWuDijCxBOkD6\nIBM1ZHqnntR2EbqgxMzdAR/VHCxuzs0FwQLWkT/BkGIeq7sjGgO9qVUQx9hc\ncT4ZlXZygrP/M5XGsWSJdLINsCoP1JYKG6NyIY8jOBJHDICfk+vo4rwpZ3DB\n4MOV8nHaASnZ3HTpmCDvXKWnnHqKsjuzLOS3Ckg5zl76OkDcvw0KYM9GlqYN\ndBZBTV61v/pn00Ga2myhGnFbTTh+O1jtiOUP+fP7uyoCHiuaqQg3+9OuRM8c\nCh5s08tZ2zUcdhV2RGrM9JASOpxZkFQxS4tEb72GgwBb/yOLddvPCRONJ35a\n+hrvDXhCW+M8U8ObVCH48aIdCnlkNfZDoxGaN2jLX8opfz5dQXIfRhft7o1E\nHX1qIeC+SS8F66jC/SfzXw5R693OhmHk1FHvFAOPdR/2sqCgcyJ8UllPQYhP\n7GSpk55DOBv6xEi4uP67OHtEKBM47gQ/ZJ7M840iJayIiBvDYo+TjF+hTRtc\n7fzCWqEKI23M6jicRLKi+V9IaX9jY8dkWFxh/O2Hms1dveYdILL6pQ7E7/pG\nSkctgGxWelhRjKdc6bvDuLbTjHU4OJJG/Ntb/PlgD2LoeNRMnBf6AEue18Fd\nkQ9x\r\n=tSXq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCC5e4O9DsI08Lc/zV+2n4/MqI+9pvMExkdhOhxikh2fAIhAIxoGrqAf2vM0n5xJL91VGUzdM/5F3J5b/GF086C17hh"}]},"_npmUser":{"name":"derhuerst","email":"mail@jannisr.de"},"directories":{},"maintainers":[{"name":"derhuerst","email":"mail@jannisr.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/socks-agent-with-socket-ttl_1.0.0_1639261331593_0.8865189741666886"},"_hasShrinkwrap":false}},"time":{"created":"2021-12-11T22:22:11.539Z","1.0.0":"2021-12-11T22:22:11.771Z","modified":"2022-04-05T03:48:37.502Z"},"maintainers":[{"name":"derhuerst","email":"mail@jannisr.de"}],"description":"Node.js SOCKS5 Agent with a configurable sockets TTL.","homepage":"https://github.com/derhuerst/socks-agent-with-socket-ttl","keywords":["agent","proxy","socks","socks5","ttl"],"repository":{"type":"git","url":"git+https://github.com/derhuerst/socks-agent-with-socket-ttl.git"},"author":{"name":"Jannis R","email":"mail@jannisr.de"},"bugs":{"url":"https://github.com/derhuerst/socks-agent-with-socket-ttl/issues"},"license":"ISC","readme":"# socks-agent-with-socket-ttl\n\n**Node.js [SOCKS5](https://en.wikipedia.org/wiki/SOCKS#SOCKS5) [Agent](https://nodejs.org/api/http.html#class-httpagent) with a configurable sockets time to live (TTL).**\n\n[![npm version](https://img.shields.io/npm/v/@derhuerst/socks-agent-with-socket-ttl.svg)](https://www.npmjs.com/package/@derhuerst/socks-agent-with-socket-ttl)\n![ISC-licensed](https://img.shields.io/github/license/derhuerst/socks-agent-with-socket-ttl.svg)\n![minimum Node.js version](https://img.shields.io/node/v/socks-agent-with-socket-ttl.svg)\n[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)\n[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)\n\n\n## Installation\n\n```shell\nnpm install @derhuerst/socks-agent-with-socket-ttl\n```\n\n\n## Usage\n\nLet's say you want to send requests through the [Tor network](https://www.torproject.org), via your locally install Tor node, which exposes a [SOCKS5](https://en.wikipedia.org/wiki/SOCKS#SOCKS5) proxy on `127.0.0.1:9050`. You have configured it to pick a new *circuit* (the Tor term for the chain of Tor nodes your traffic is sent through) every 60s, *usually* giving you a new public IP every time; But that only applies to new sockets you're creating, exiting ones will keep their old circuit and thus their old public IP. Therefore, you want to keep sockets open (e.g. for [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive)) for 60s, to improve response latency, but closes them every 60s to make use of your changing public IP.\n\n```js\nconst socksAgentWithSocketTTL = require('@derhuerst/socks-agent-with-socket-ttl')\nconst fetch = require('node-fetch')\n\nconst torSocks5Agent = socksAgentWithSocketTTL({\n\t// connect to local Tor node\n\thost: '127.0.0.1',\n\tport: 9050,\n\t// close sockets when they get 60s old\n\tsocketTTL: 60 * 1000,\n})\n\nwhile (true) {\n\tconst res = await fetch('https://wtfismyip.com/text', {\n\t\tagent: torSocks5Agent,\n\t\theaders: {\n\t\t\t'user-agent': '<identifier of your program>',\n\t\t\t'connection': 'keep-alive',\n\t\t},\n\t})\n\tconst ip = await res.text()\n\tconsole.log('public IP is', ip)\n\n\tawait new Promise(r => setTimeout(r, 10 * 1000)) // wait for 10s\n}\n```\n\n\n## Contributing\n\nIf you have a question or need support using `socks-agent-with-socket-ttl`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use [the issues page](https://github.com/derhuerst/socks-agent-with-socket-ttl/issues).\n","readmeFilename":"readme.md"}