The `zone-file` package provides an RFC1035-compliant JavaScript library for both parsing and generating DNS zone files. It supports a comprehensive range of common DNS record types, including Start of Authority (SOA), Name Server (NS), A records (IPv4), AAAA records (IPv6), Canonical Name (CNAME), Mail Exchange (MX), Pointer (PTR), Service (SRV), Text (TXT), and Uniform Resource Identifier (URI) records, alongside the critical `$ORIGIN` keyword for defining the zone's base domain. The current and only stable version available on npm is 1.0.0, which was last published in January 2019. While the library itself is functional for its stated purpose, the lack of new releases under the `zone-file` npm package for several years, despite related code being developed under the `stacks-network/zone-file-js` GitHub repository, indicates that the specific npm package `zone-file` is effectively abandoned. Developers should be aware of this infrequent update cadence and consider potential alternatives for ongoing maintenance and feature support.
npm install zone-fileVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to parse an existing DNS zone file string into a JavaScript object, modify the object by adding a new CNAME record, and then generate an updated zone file string.
Consider migrating to a more actively maintained DNS zone file parsing library if long-term support, security patches, or new features are required. Inspect `stacks-network/zone-file-js` for alternative distribution methods or package names.
Always validate generated or parsed zone files using external tools (e.g., `named-checkzone` from BIND, online validators) before deployment. Carefully review the input data structure for `generate` and the output of `parseZone`.
For CommonJS, use `const zonefile = require('zone-file'); const parsed = zonefile.parseZone(...);`. For ESM, ensure your `package.json` has `"type": "module"` or use a bundler configured for module resolution.Review the `zoneFileContent` string for correct record types, hostnames (e.g., trailing dots for FQDNs), TTLs, and other DNS specific syntax. Use a DNS zone file validator to pinpoint the exact issue.
Ensure you are using the correct import statement: `import { parseZone, generate } from 'zone-file';` for ESM, or `const { parseZone, generate } = require('zone-file');` for CommonJS.No dependency data recorded yet.