pom-parser is a Node.js library designed for parsing Java/Maven `pom.xml` files, converting their hierarchical XML structure into a navigable JavaScript object. Currently at version `1.2.0`, the package provides an API to extract critical project metadata, including group IDs, artifact IDs, versions, and build configurations, crucial for environments transitioning Java applications to Node.js or integrating with existing Maven-based repository systems like Nexus. It merges XML attributes directly into parent elements and offers the flexibility to provide custom parsing options, leveraging `xml2js` internally. While no explicit release cadence is stated, updates focus on dependency maintenance and adopting modern JavaScript features like native Promises, ensuring compatibility and stability.
npm install pom-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a `pom.xml` file, showing both the traditional callback and the modern Promise-based (async/await) approaches. It outputs parts of the parsed XML and JSON object.
To use Promises, call `pomParser.parse(options)` and handle the returned Promise with `.then().catch()` or `await` it. If providing a callback, the function will behave as before.
Prefer `const pomParser = require('pom-parser');` for optimal compatibility in Node.js environments. For ESM, you might need dynamic import (`import('pom-parser')`) or bundler-specific configurations.Consult the `xml2js` documentation (e.g., for `parseString` options) when passing custom options to `pomParser.parse(opts)` to ensure desired XML parsing behavior. Default options are set for typical `pom.xml` structures.
Verify that the `filePath` in your options object is correct and accessible by the Node.js process. Use `path.resolve()` or `path.join()` for robust path handling.
Inspect the `pom.xml` file for syntax errors or unexpected content. Adjust `xml2js` parsing options via the `opts` argument to `pomParser.parse` if the XML structure deviates from standard patterns but is valid.
Ensure you are using `const pomParser = require('pom-parser');` and then calling `pomParser.parse(...)`. If using ESM, check your `import` statement and transpilation/bundling setup.