zonefile-parser is a JavaScript module designed for parsing DNS zone configuration files. It leverages a grammar generated by PEG.js to accurately interpret standard zonefile syntax. The package, currently at version 1.0.1, handles common DNS record types such as SOA, TXT (including multi-line records), SRV, MX, CNAME, NS, A, and AAAA records. It differentiates itself by having no runtime dependencies, making it a lightweight solution for both Node.js and browser environments (with a smaller 'small.js' variant for browser use cases). The project appears to be stable with a low release cadence, primarily focusing on its core parsing functionality without frequent updates to new DNS standards, making it suitable for established zonefile formats.
npm install zonefile-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a multi-record DNS zonefile using both the default 'fast' and the smaller 'small' parsers provided by the library, outputting the structured JSON representation of the records.
Explicitly import `require('zonefile-parser/small')` when targeting smaller bundles for browser or client-side use cases. Otherwise, `require('zonefile-parser')` is the default and recommended for Node.js.For highly dynamic or cutting-edge DNS configurations, validate the parser's output against known good data or consider alternative, more actively maintained DNS parsing libraries. Review the upstream PEG.js grammar (`https://github.com/tableflip/zonefile-pegjs`) for supported features.
For ESM projects, use `import parser from 'zonefile-parser';` and rely on your bundler (e.g., Webpack, Rollup, esbuild) or Node.js's native ESM loader to handle the CJS compatibility. If issues arise, consider a CJS wrapper or ensure your build tools are correctly configured for CJS interop.
Carefully review the offending line in the zonefile content. Ensure all records adhere to standard DNS zonefile format, including proper spacing, quotes for TXT records, and correct record type syntax. Check for unclosed parentheses in SOA records or missing mandatory fields.
If in an ESM context, change `const parser = require('zonefile-parser')` to `import parser from 'zonefile-parser'`. If running in a browser, ensure you are using a bundler (like Webpack, Rollup) that handles CommonJS modules.Ensure you are importing the default export correctly: `const parser = require('zonefile-parser')` for CJS or `import parser from 'zonefile-parser'` for ESM. Double-check the path, especially if using `zonefile-parser/small`.No dependency data recorded yet.