Registry / serialization / pom-parser

pom-parser

JSON →
library0.0.2jsnpmunverified

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-parser
INSTALL
IMPORT
SIG · POM-PARSER
P
pom-parser
serializationjavascriptv0.0.2
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.

pomParser
const pomParser = require('pom-parser');
import pomParser from 'pom-parser';
This library is primarily CommonJS. Direct ESM 'import' may require bundler configuration or result in an object with a default property.
parse
pomParser.parse(opts, callback);
import { parse } from 'pom-parser';
`parse` is a method of the default exported `pomParser` object, not a named export. It supports both callback and Promise-based usage since v1.2.0.

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.

const pomParser = require('pom-parser'); const path = require('path'); const fs = require('fs'); // Create a dummy pom.xml for demonstration const dummyPomContent = `<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-app</artifactId> <version>1.0.0</version> <name>My App</name> <properties> <java.version>11</java.version> </properties> <build> <finalName>my-app</finalName> </build> </project>`; const pomFilePath = path.join(__dirname, 'temp-pom.xml'); fs.writeFileSync(pomFilePath, dummyPomContent); const opts = { filePath: pomFilePath, // Other xml2js parsing options can be added here }; // Using callback pattern (still supported) pomParser.parse(opts, function(err, pomResponse) { if (err) { console.error("ERROR (callback): " + err); return; } console.log("--- Callback Result ---"); console.log("XML: " + pomResponse.pomXml.substring(0, 100) + '...'); console.log("OBJECT: " + JSON.stringify(pomResponse.pomObject.project.name, null, 2)); }); // Using Promise pattern (since v1.2.0) async function parsePomWithPromise() { try { const pomResponse = await pomParser.parse(opts); console.log("\n--- Promise Result ---"); console.log("XML: " + pomResponse.pomXml.substring(0, 100) + '...'); console.log("OBJECT: " + JSON.stringify(pomResponse.pomObject.project.version, null, 2)); } catch (err) { console.error("ERROR (promise): " + err); } finally { // Clean up the dummy file fs.unlinkSync(pomFilePath); } } parsePomWithPromise();
Debug
Known issues
gotchaSince `v1.2.0`, `pom-parser` uses native Promises internally, and its `parse` function will return a Promise if the callback argument is omitted. While the callback interface remains supported, users expecting to `await` the result should call `pomParser.parse(opts)` without a callback.
fix
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.
affects: >=1.2.0
gotchaThis library is distributed as a CommonJS module (`require`). Attempting to use `import pomParser from 'pom-parser'` in an ESM context directly may lead to unexpected results or require specific `package.json` `type: module` configurations or bundler setups.
fix
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.
affects: >=1.0.0
gotchaThe `parse` function exposes options directly from its underlying `xml2js` dependency. Misunderstanding or incorrectly configuring `xml2js` options can lead to unexpected parsing behavior or errors.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open '[your-file-path]/pom.xml'
The `filePath` option provided to `pomParser.parse` does not point to an existing `pom.xml` file.
fix
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.
ERROR: [XML parsing error message, e.g., 'Non-whitespace content after end-tag']
The `pom.xml` file being parsed is malformed or contains unexpected XML structures that `xml2js` cannot process with the current options.
fix
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.
TypeError: pomParser.parse is not a function
This usually indicates an incorrect import or `require` statement, where `pomParser` does not correctly resolve to the module's export, or you are trying to destructure it incorrectly in CommonJS.
fix
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.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
xml2jsrequiredCore dependency for XML parsing, its options are exposed and underpin the parsing logic.
Agent activity
2 hits · last 30 days
node
2
Resources
pom-parser — npm install pom-parser · libregistry