{"id":14745081,"url":"https://github.com/lsongdev/node-dns","last_synced_at":"2026-05-26T02:01:09.695Z","repository":{"id":37622897,"uuid":"71681900","full_name":"lsongdev/node-dns","owner":"lsongdev","description":":globe_with_meridians:  DNS Server and Client Implementation in Pure JavaScript with no dependencies.","archived":false,"fork":false,"pushed_at":"2025-01-02T01:53:02.000Z","size":184,"stargazers_count":554,"open_issues_count":8,"forks_count":69,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-12T00:12:01.339Z","etag":null,"topics":["dns","dns-client","dns-protocol","dns-server","dns2","lookup","network","networking","nodejs","tcp","udp"],"latest_commit_sha":null,"homepage":"https://npmjs.org/dns2","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lsongdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"song940","patreon":"song940","open_collective":"song940","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://git.io/fjRcB"}},"created_at":"2016-10-23T04:36:42.000Z","updated_at":"2025-04-22T18:01:32.000Z","dependencies_parsed_at":"2023-11-12T16:25:35.172Z","dependency_job_id":"0c66f4c8-e970-43d7-9001-7c13c24f2093","html_url":"https://github.com/lsongdev/node-dns","commit_stats":{"total_commits":76,"total_committers":18,"mean_commits":4.222222222222222,"dds":0.6052631578947368,"last_synced_commit":"ded06caf7ec3c7a56a32010a2f950b006609881b"},"previous_names":["lsongdev/node-dns","song940/node-dns"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsongdev%2Fnode-dns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsongdev%2Fnode-dns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsongdev%2Fnode-dns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lsongdev%2Fnode-dns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lsongdev","download_url":"https://codeload.github.com/lsongdev/node-dns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328385,"owners_count":22052632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","dns-client","dns-protocol","dns-server","dns2","lookup","network","networking","nodejs","tcp","udp"],"created_at":"2024-09-14T15:01:09.274Z","updated_at":"2026-05-26T02:01:09.631Z","avatar_url":"https://github.com/lsongdev.png","language":"JavaScript","funding_links":["https://github.com/sponsors/song940","https://patreon.com/song940","https://opencollective.com/song940","https://git.io/fjRcB"],"categories":["JavaScript","Networking Protocols"],"sub_categories":[],"readme":"# dns2 \n\n![NPM version](https://img.shields.io/npm/v/dns2.svg?style=flat)\n[![Node.js CI](https://github.com/song940/node-dns/actions/workflows/node.js.yml/badge.svg)](https://github.com/song940/node-dns/actions/workflows/node.js.yml)\n\n\u003e A DNS Server and Client Implementation in Pure JavaScript with no dependencies.\n\n### Features\n\n+ Server and Client\n+ Lot of Type Supported\n+ Extremely lightweight\n+ DNS over UDP, TCP, HTTPS Supported\n\n### Installation\n\n```bash\n$ npm install dns2\n```\n\n### DNS Client (default UDP)\n\nLookup any records available for the domain `lsong.org`. \nDNS client will use UDP by default.\n\n```js\nconst dns2 = require('dns2');\n\nconst options = {\n  // available options\n  // dns: dns server ip address or hostname (string),\n  // port: dns server port (number),\n  // recursive: Recursion Desired flag (boolean, default true, since \u003e v1.4.2)\n};\nconst dns = new dns2(options);\n\n(async () =\u003e {\n  const result = await dns.resolveA('google.com');\n  console.log(result.answers);\n})();\n```\n\nAnother way to instanciate dns2 UDP Client:\n\n```js\nconst { UDPClient } = require('dns2');\n\nconst resolve = UDPClient();\n\n(async () =\u003e {\n  const response = await resolve('google.com')\n  console.log(response.answers);\n})();\n```\n\n### DNS Client (TCP)\n\nLookup any records available for the domain `lsong.org`. By default, DNS requests will use UDP.\n\n```js\nconst { TCPClient } = require('dns2');\n\nconst resolve = TCPClient();\n\n(async () =\u003e {\n  try {\n    const response = await resolve('lsong.org')\n    console.log(response.answers);\n  } catch(error) {\n    // some DNS servers (i.e cloudflare 1.1.1.1, 1.0.0.1) \n    // may send an empty response when using TCP\n    console.log(error);\n  }\n})();\n```\n\n### Client Custom DNS Server\n\nYou can pass your own DNS Server.\n\n```js\nconst { TCPClient } = require('dns2');\n\nconst resolve = TCPClient({\n  dns: '1.1.1.1'\n});\n\n(async () =\u003e {\n  try {\n    const result = await resolve('google.com');\n    console.log(result.answers);\n  } catch(error) {\n    console.log(error);\n  }\n})();\n```\n\n### System DNS Server\n\nYou can use the first DNS server from your OS with native node dns.\n\n```js\nconst dns = require('dns');\nconst { TCPClient } = require('dns2');\n\nconst resolve = TCPClient({\n  dns: dns.getServers()[0]\n});\n\n(async () =\u003e {\n  try {\n    const result = await resolve('google.com');\n    console.log(result.answers);\n  } catch(error) {\n    console.log(error);\n  }\n})();\n```\n\n### Example Server\n\n```js\nconst dns2 = require('dns2');\n\nconst { Packet } = dns2;\n\nconst server = dns2.createServer({\n  udp: true,\n  handle: (request, send, rinfo) =\u003e {\n    const response = Packet.createResponseFromRequest(request);\n    const [ question ] = request.questions;\n    const { name } = question;\n    response.answers.push({\n      name,\n      type: Packet.TYPE.A,\n      class: Packet.CLASS.IN,\n      ttl: 300,\n      address: '8.8.8.8'\n    });\n    send(response);\n  }\n});\n\nserver.on('request', (request, response, rinfo) =\u003e {\n  console.log(request.header.id, request.questions[0]);\n});\n\nserver.on('requestError', (error) =\u003e {\n  console.log('Client sent an invalid request', error);\n});\n\nserver.on('listening', () =\u003e {\n  console.log(server.addresses());\n});\n\nserver.on('close', () =\u003e {\n  console.log('server closed');\n});\n\nserver.listen({\n  // Optionally specify port, address and/or the family of socket() for udp server:\n  udp: { \n    port: 5333,\n    address: \"127.0.0.1\",\n  },\n  \n  // Optionally specify port and/or address for tcp server:\n  tcp: { \n    port: 5333,\n    address: \"127.0.0.1\",\n  },\n});\n\n// eventually\nserver.close();\n```\n\nThen you can test your DNS server:\n\n```bash\n$ dig @127.0.0.1 -p5333 lsong.org\n```\n\nNote that when implementing your own lookups, the contents of the query\nwill be found in `request.questions[0].name`.\n\n### Relevant Specifications\n\n+ [RFC-1034 - Domain Names - Concepts and Facilities](https://tools.ietf.org/html/rfc1034)\n+ [RFC-1035 - Domain Names - Implementation and Specification](https://tools.ietf.org/html/rfc1035)\n+ [RFC-2782 - A DNS RR for specifying the location of services (DNS SRV)](https://tools.ietf.org/html/rfc2782)\n+ [RFC-7766 - DNS Transport over TCP - Implementation Requirements](https://tools.ietf.org/html/rfc7766)\n+ [RFC-8484 - DNS Queries over HTTPS (DoH)](https://tools.ietf.org/html/rfc8484)\n\n### Contributing\n\n- Fork this Repo first\n- Clone your Repo\n- Install dependencies by `$ npm install`\n- Checkout a feature branch\n- Feel free to add your features\n- Make sure your features are fully tested\n- Publish your local branch, Open a pull request\n- Enjoy hacking \u003c3\n\n### MIT license\n\nCopyright (c) 2016 LIU SONG \u003csong940@gmail.com\u003e \u0026 [contributors](https://github.com/song940/node-dns/graphs/contributors).\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS,\" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsongdev%2Fnode-dns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flsongdev%2Fnode-dns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flsongdev%2Fnode-dns/lists"}