# @mimik/address-helper

> IP Address helper for mimik microservices

Latest version **2.1.2** (published 2026-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mimik/address-helper
pnpm add @mimik/address-helper
yarn add @mimik/address-helper
bun add @mimik/address-helper
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2026-07-13 |
| First published | 2018-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=24.0.0 |
| Dependencies | 1 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mimik technology inc |
| Maintainers | mimik-npm-editor, hofachiang, miburger, mimikopensource, sasan.raisdana |
| Keywords | mimik, microservice |

## Links

- npm: https://www.npmjs.com/package/@mimik/address-helper
- Repository: https://bitbucket.org/mimiktech/address-helper
- Homepage: https://bitbucket.org/mimiktech/address-helper#readme
- Issues: https://bitbucket.org/mimiktech/address-helper/issues
- npm.io page: https://npm.io/package/@mimik/address-helper

## Dependencies (1)

- [ipaddr.js](https://npm.io/package/ipaddr.js.md) 2.4.0

## Recent versions

- 2.1.2 (latest) — 2026-07-13
- 2.1.1 — 2026-06-23
- 2.0.9 — 2026-03-22
- 2.0.8 — 2026-03-12
- 2.0.7 — 2026-02-23
- 2.0.6 — 2026-02-23
- 2.0.5 — 2025-08-12
- 2.0.4 — 2025-07-17
- 2.0.3 — 2025-03-25
- 2.0.2 — 2025-03-14
- 2.0.1 — 2025-03-14
- 2.0.0 — 2025-02-17
- 1.6.10 — 2023-12-05
- 1.6.9 — 2023-04-13
- 1.6.8 — 2023-04-12
- … 13 more at https://npm.io/package/@mimik/address-helper/versions

## README

<a name="module_address-helper"></a>

## address-helper
**Example**  
```js
import addressHelper from '@mimik/address-helper';
// or
import { getAddressByType, hrefId, addressTypeMaker, addressFormat, addressFromNode, getAddress, updateAddresses, publicIpFromRequest, publicIpFromNode } from '@mimik/address-helper';
```

* [address-helper](#module_address-helper)
    * [~getAddressByType(type, addresses)](#module_address-helper..getAddressByType) ⇒ <code>object</code>
    * [~hrefId(serverSettings, basePath, resource, id)](#module_address-helper..hrefId) ⇒ <code>URL.&lt;string&gt;</code>
    * [~addressTypeMaker(type, href, routingPort, hostname)](#module_address-helper..addressTypeMaker) ⇒ <code>object</code>
    * [~addressFormat(type, protocol, ip, port, pathname, routingPort)](#module_address-helper..addressFormat) ⇒ <code>object</code>
    * [~addressFromNode(type, ip, node, routingPort)](#module_address-helper..addressFromNode) ⇒ <code>object</code>
    * [~getAddress(node, localLinkNetworkId)](#module_address-helper..getAddress) ⇒ <code>object</code>
    * [~updateAddresses(type, newAddress, addresses)](#module_address-helper..updateAddresses) ⇒ <code>Array.&lt;object&gt;</code>
    * [~publicIpFromNode(node)](#module_address-helper..publicIpFromNode) ⇒ <code>IP.&lt;string&gt;</code>
    * [~publicIpFromRequest(req)](#module_address-helper..publicIpFromRequest) ⇒ <code>IP.&lt;string&gt;</code>

<a name="module_address-helper..getAddressByType"></a>

### address-helper~getAddressByType(type, addresses) ⇒ <code>object</code>
Get the address by type from an array of addresses.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Returns**: <code>object</code> - Address by type.  
**Category**: sync  
**Warning**: This function mutates the matched address object if `hostname` is missing, deriving it from `href`.  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of address to return. |
| addresses | <code>Array.&lt;object&gt;</code> | Addresses from which the specific address is retrieved. |

<a name="module_address-helper..hrefId"></a>

### address-helper~hrefId(serverSettings, basePath, resource, id) ⇒ <code>URL.&lt;string&gt;</code>
Generate a href based on the given parameters.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Returns**: <code>URL.&lt;string&gt;</code> - Generated href.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| serverSettings | <code>object</code> | Configuration to use to generate the href. Requires `public.protocol`; optionally `public.domainName`. When `public.domainName` is absent, `ip.public` (or `ip.local`) and `port` are required to build the host. |
| basePath | <code>PATH.&lt;string&gt;</code> | Base path to use to generate the href. |
| resource | <code>PATH.&lt;string&gt;</code> | Resource to use to generate the href. |
| id | <code>UUID.&lt;string&gt;</code> | Id to use to generate the href. |

<a name="module_address-helper..addressTypeMaker"></a>

### address-helper~addressTypeMaker(type, href, routingPort, hostname) ⇒ <code>object</code>
Generate an address using the given parameters.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Returns**: <code>object</code> - Generated address.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type to use to generate the address to return. |
| href | <code>URL.&lt;string&gt;</code> | URL to use to generate the address to return. |
| routingPort | <code>string</code> | Routing port to generate the address to return. |
| hostname | <code>string</code> | Hostname to be used for the URL. |

<a name="module_address-helper..addressFormat"></a>

### address-helper~addressFormat(type, protocol, ip, port, pathname, routingPort) ⇒ <code>object</code>
Return an address using the given parameters.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Returns**: <code>object</code> - Generated address.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type to use to generate the address to return. |
| protocol | <code>string</code> | Protocol to use to generate the address to return. |
| ip | <code>IP.&lt;string&gt;</code> | IP to use to generate the address to return. A raw IPv6 literal is automatically bracketed (e.g. `::1` becomes `[::1]`). |
| port | <code>string</code> | Port to use to generate the address to return. |
| pathname | <code>PATH.&lt;string&gt;</code> | Path to add to generate the address to return. |
| routingPort | <code>string</code> | Port to use to set the address to return. |

<a name="module_address-helper..addressFromNode"></a>

### address-helper~addressFromNode(type, ip, node, routingPort) ⇒ <code>object</code>
Return an address corresponding to the given parameters.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Summary**: If the type is `proxy`, an inversion using `routingPort` is done.  
**Returns**: <code>object</code> - Generated address corresponding to the given parameters.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of address to return. |
| ip | <code>IP.&lt;string&gt;</code> | IP address used to generate the address to return. |
| node | <code>object</code> | Node to use to generate the address to return. |
| routingPort | <code>string</code> | Routing port to use to generate the address to return. |

<a name="module_address-helper..getAddress"></a>

### address-helper~getAddress(node, localLinkNetworkId) ⇒ <code>object</code>
Return the address to be used to reach the node.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Summary**: If `localLinkNetworkId` is present and if the node's ID matches the given one, return the local address.
Otherwise return the proxy address, if it exists, or the public address.  
**Returns**: <code>object</code> - Address to use to reach the node.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| node | <code>object</code> | Node from which to get the address. |
| localLinkNetworkId | <code>string</code> | Id of the link local network to get the address from. |

<a name="module_address-helper..updateAddresses"></a>

### address-helper~updateAddresses(type, newAddress, addresses) ⇒ <code>Array.&lt;object&gt;</code>
Add a new address of a specific type in the array of addresses.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Summary**: If `newAddress` is falsy, the existing address of the given type is removed.  
**Returns**: <code>Array.&lt;object&gt;</code> - Updated array of addresses.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | Type of address to add. |
| newAddress | <code>object</code> | New address to add to the array of addresses. |
| addresses | <code>Array.&lt;object&gt;</code> | Initial array of addresses to which the new address will be added. |

<a name="module_address-helper..publicIpFromNode"></a>

### address-helper~publicIpFromNode(node) ⇒ <code>IP.&lt;string&gt;</code>
Get the public IP address from the registering node.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Summary**: If node is not defined or if there's no public address return `null`.  
**Returns**: <code>IP.&lt;string&gt;</code> - Public IP address of the node.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| node | <code>object</code> | The node containing the public IP address. |

<a name="module_address-helper..publicIpFromRequest"></a>

### address-helper~publicIpFromRequest(req) ⇒ <code>IP.&lt;string&gt;</code>
Get the public IP address from the http request.

**Kind**: inner method of [<code>address-helper</code>](#module_address-helper)  
**Summary**: Uses the leftmost `x-forwarded-for` entry when present. That value is client-supplied and can be spoofed
unless a trusted edge proxy sanitizes the header, so it should not be relied upon for rate limiting or allowlisting.  
**Returns**: <code>IP.&lt;string&gt;</code> - Public IP address of the component making the request.

| Env variable name | Description | Default | Comments |
| ----------------- | ----------- | ------- | -------- |
| IPV4 | when set and non-null, will translate an IPV6 address into IPV4 address when possible | | `::1` will be translated to `127.0.0.1` |

If the environment variable IPV4 is set (to any non-null value), the ip address will be translated to IPV4 address when possible, and `::1` will be translated to `127.0.0.1`.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| req | <code>object</code> | The http request to get the public IP address. |

---
_Source: https://npm.io/package/@mimik/address-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
