# @opi_pib/node-utility

> Node utility

Latest version **3.0.3** (published 2025-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @opi_pib/node-utility
pnpm add @opi_pib/node-utility
yarn add @opi_pib/node-utility
bun add @opi_pib/node-utility
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2025-11-27 |
| First published | 2022-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24.0.0 |
| Dependencies | 8 |
| Unpacked size | 24 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Dawid Lubowiecki |
| Maintainers | national-information-processing-institute-opi-pib, dlubowiecki, mpaduszynski |
| Keywords | node utility, node notify, node http helpers |

## Links

- npm: https://www.npmjs.com/package/@opi_pib/node-utility
- Repository: https://github.com/OPI-PIB/node-utility
- Homepage: https://github.com/OPI-PIB/node-utility#readme
- Issues: https://github.com/OPI-PIB/node-utility/issues
- npm.io page: https://npm.io/package/@opi_pib/node-utility

## Dependencies (8)

- [qs](https://npm.io/package/qs.md) ^6.0.0
- [express](https://npm.io/package/express.md) ^5.0.0
- [@types/qs](https://npm.io/package/@types/qs.md) ^6.0.0
- [http-proxy](https://npm.io/package/http-proxy.md) ^1.0.0
- [@types/express](https://npm.io/package/@types/express.md) ^4.0.0
- [@types/http-proxy](https://npm.io/package/@types/http-proxy.md) ^1.0.0
- [@opi_pib/ts-utility](https://npm.io/package/@opi_pib/ts-utility.md) ^2.0.0
- [http-proxy-middleware](https://npm.io/package/http-proxy-middleware.md) ^2.0.0

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 3.0.3 (latest) — 2025-11-27
- 3.0.2 — 2025-11-27
- 3.0.1 — 2025-11-04
- 3.0.0 — 2025-11-04
- 2.3.0 — 2025-06-24
- 2.2.0 — 2025-06-24
- 2.1.0 — 2024-11-29
- 2.0.0 — 2024-09-25
- 1.2.1 — 2024-06-26
- 1.2.0 — 2024-06-24
- 1.1.14 — 2024-05-06
- 1.1.13 — 2024-02-26
- 1.1.12 — 2023-11-14
- 1.1.11 — 2023-10-20
- 1.1.10 — 2023-10-19
- … 17 more at https://npm.io/package/@opi_pib/node-utility/versions

## README

# Node Utility

- [Install](#install)
- [Notify](#notify)
- [HttpProxyMiddleware](#httpproxymiddleware)
- [HttpAdapters](#httpadapters)

## Install

```
npm install @opi_pib/node-utility
```

## Notify

### Usage

```javascript
Notify.success({ message: 'message' });
Notify.warning({ message: 'message' });
Notify.info({ message: 'message' });
Notify.error({ message: 'message', error: new Error('Some error') });
```

## Mock server

npm scripts

```
npm i -D @stoplight/prism-cli
```

```
"mock:server": "prism mock --port=3010 ./dist/index.json",
```

## HttpProxyMiddleware

Proxy middleware for express server

### Usage

proxy.ts

```javascript
import { HttpProxyMiddleware } from '@opi_pib/node-utility';

const handlers = [SystemInfo.processRes];

HttpProxyMiddleware.run(3010, 3011, handlers);
```

npm scripts

```
"mock:server": "ts-node proxy.ts",
```

## HttpAdapters

### HttpAdapters.replaceResponseBody()

Replace response with new value of body

#### Usage

```javascript
import {
	HttpAdapters,
	IncomingMessage,
	ProxyRequest,
	ServerResponse,
} from '@opi_pib/node-utility';

export class SystemInfo {
	static processRes(
		proxyRes: IncomingMessage,
		req: ProxyRequest,
		res: ServerResponse,
	) {
		if (Route.pathMatch(req, '^/system/info$')) {
			return HttpAdapters.replaceResponseBody(infoElementDto, proxyRes, res);
		}
	}
}
```

### HttpAdapters.replaceResponseBodyFromJsonFile()

Replace response with new value of body from json file

#### Usage

```javascript
export class SystemInfo {
	static processRes(
		proxyRes: IncomingMessage,
		req: ProxyRequest,
		res: ServerResponse,
	) {
		if (Route.pathMatch(req, '^/system/info$')) {
			return HttpAdapters.replaceResponseBodyFromJsonFile('./infoElementDto.json', proxyRes, res);
		}
	}
}
```

### HttpAdapters.replaceResponseBodyFromFile()

Replace response with content of file

#### Usage

```javascript
export class SystemInfo {
	static processRes(
		proxyRes: IncomingMessage,
		req: ProxyRequest,
		res: ServerResponse,
	) {
		if (Route.pathMatch(req, '^/system/info$')) {
			return HttpAdapters.replaceResponseBodyFromFile('./infoElementDto.pdf', proxyRes, res);
		}
	}
}
```

### HttpAdapters.toQueryString()

Convert object into queryString

#### Usage

```javascript
const result = HttpAdapters.toQueryString({
	a: 'b',
	c: 1,
	d: undefined,
	e: null
});

expect('a=b&c=1').toEqual(result);
```

### HttpAdapters.stringify()

Stringify value

#### Usage

```javascript
const result = HttpAdapters.stringify({
	a: 'b',
	c: 1,
	d: undefined,
	e: null
});

expect('{"a":"b","c":1}').toEqual(result);
```

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