Registry / serialization / zone-file

zone-file

JSON →
library0.1.5jsnpmunverified

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-file
INSTALL
IMPORT
SIG · ZONE-FILE
Z
zone-file
serializationjavascriptv0.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseZone
import { parseZone } from 'zone-file';
const { parseZone } = require('zone-file');
The original `zone-file` v1.0.0 was primarily CommonJS. Modern Node.js projects should configure their environment for ESM. For older environments, use `require`.
generate
import { generate } from 'zone-file';
const { generate } = require('zone-file');
The `generate` function creates a zone file string from a JavaScript object. Ensure your environment supports ESM imports for newer syntax.

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.

import { parseZone, generate } from 'zone-file'; const zoneFileContent = ` $ORIGIN example.com. $TTL 3600 @ IN SOA ns1.example.com. hostmaster.example.com. ( 2023010101 ; Serial 7200 ; Refresh 3600 ; Retry 1209600 ; Expire 3600 ; Minimum TTL ) @ IN NS ns1.example.com. @ IN NS ns2.example.com. @ IN A 192.0.2.1 www IN A 192.0.2.2 mail IN MX 10 mail.example.com. mail IN A 192.0.2.3 `; try { // Parse the zone file content into a JavaScript object const parsedZone = parseZone(zoneFileContent); console.log('Parsed Zone Object:'); console.log(JSON.stringify(parsedZone, null, 2)); // Add a new record to the parsed object parsedZone.cname = parsedZone.cname || []; parsedZone.cname.push({ name: 'blog', alias: 'www' }); // Generate a new zone file string from the modified object const generatedZone = generate(parsedZone); console.log('\nGenerated Zone File with new CNAME record:'); console.log(generatedZone); } catch (error) { console.error('Error processing zone file:', error.message); }
Debug
Known issues
breakingThe `zone-file` npm package (v1.0.0) has not been updated since January 2019. While the underlying code may be developed under a different GitHub repository (`stacks-network/zone-file-js`), no new versions have been published to npm under this package name. This means it lacks recent bug fixes, performance improvements, and security updates.
fix
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.
affects: 1.0.0
gotchaIncorrectly formatted zone file input can lead to parsing errors or the generation of invalid DNS configurations, which can cause significant service disruptions. DNS zone files are highly sensitive to syntax, including trailing dots on FQDNs and correct record structures.
fix
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`.
affects: >=1.0.0
gotchaThe `zone-file` package uses CommonJS `require()` internally and exports functions for `import` in modern JavaScript environments. If using `require()` directly, ensure your environment is set up for CommonJS or that you destructure correctly.
fix
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.
affects: 1.0.0
Errors
Common errors & fixes
Error: Invalid zone file syntax at line X: Y
The input string provided to `parseZone` contains malformed DNS record entries or overall syntax errors according to RFC1035.
fix
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.
TypeError: zonefile.parseZone is not a function
The module was imported incorrectly, or the `zonefile` variable does not properly reference the functions exported by the package.
fix
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.
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
28
OpenAI (training)
1
Resources
zone-file — npm install zone-file · libregistry