Semver icon

Semver

Semantic Versioning utilities for version management

Overview

The node provides semantic versioning (semver) utilities focused on comparing two version strings in various ways. The "Reverse Compare" operation specifically compares two versions and returns the result of a reverse comparison, which means it compares version2 against version1 rather than the usual version1 against version2.

This node is useful when you need to determine the ordering or precedence of software versions, for example:

  • Deciding if a newer version is available by comparing current and candidate versions.
  • Sorting versions in descending order based on semver rules.
  • Implementing deployment or upgrade logic that depends on version precedence.

Practical example: Given version1 = "1.2.3" and version2 = "1.2.4", the Reverse Compare operation will return 1 because "1.2.4" is greater than "1.2.3" when compared from version2 to version1.

Properties

Name Meaning
Version 1 The first version string to compare (e.g., "1.2.3").
Version 2 The second version string to compare (e.g., "1.2.4").
Options Collection of optional flags affecting parsing and comparison:
- Loose: Whether to use loose parsing for version strings (boolean).
- Include Prerelease: Whether to include prerelease versions in range matching (boolean).
- RTL (Right to Left): Only shown for coercion resource; ignored here.

Output

The output JSON contains the following structure:

{
  "operation": "rcompare",
  "version1": "string",
  "version2": "string",
  "result": number
}
  • operation: The name of the operation performed ("rcompare").
  • version1: The first input version string.
  • version2: The second input version string.
  • result: A numeric value indicating the comparison result:
    • 1 if version2 is greater than version1,
    • -1 if version2 is less than version1,
    • 0 if both versions are equal.

No binary data is produced by this node.

Dependencies

  • This node relies on the external semver library for all version parsing and comparison logic.
  • No external API keys or services are required.
  • No special environment variables or n8n credentials are needed.

Troubleshooting

  • Invalid version strings: If either version1 or version2 is not a valid semver string, the comparison may fail or return unexpected results. Ensure inputs conform to semantic versioning format.
  • Loose parsing option: Enabling loose parsing can allow non-standard version strings but might lead to ambiguous comparisons.
  • Error messages: Errors typically indicate invalid input versions or unknown resources/operations. Verify that the resource is set to "comparison" and operation to "rcompare".
  • Continue On Fail: If enabled, errors for individual items will be returned as error messages in the output JSON instead of stopping execution.

Links and References

Discussion