# @homeofthings/node-utils

> HomeOfThings - Node Utils: various utilities and common types

Latest version **1.0.8** (published 2026-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @homeofthings/node-utils
pnpm add @homeofthings/node-utils
yarn add @homeofthings/node-utils
bun add @homeofthings/node-utils
```

## Health

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

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2026-10-17 |
| First published | 2023-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=22.22.2 |
| Dependencies | 5 |
| Unpacked size | 44.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | Guenter Sandner |
| Maintainers | gms1 |
| Keywords | lru-cache, async-context |

## Links

- npm: https://www.npmjs.com/package/@homeofthings/node-utils
- Repository: https://github.com/gms1/HomeOfThings
- Issues: https://github.com/gms1/HomeOfThings/issues
- npm.io page: https://npm.io/package/@homeofthings/node-utils

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^6.0.1
- [debug](https://npm.io/package/debug.md) ^4.4.3
- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [config](https://npm.io/package/config.md) ^5.0.1
- [type-fest](https://npm.io/package/type-fest.md) ^5.10.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2026-10-17
- 1.0.7 — 2026-08-16
- 1.0.6 — 2026-06-07
- 1.0.5 — 2026-03-19
- 1.0.4 — 2025-04-26
- 1.0.3 — 2024-12-22
- 1.0.2 — 2024-10-26
- 1.0.1 — 2024-01-05
- 1.0.0 — 2023-12-18

## README

[![npm version](https://badge.fury.io/js/%40homeofthings%2Fnode-utils.svg)](https://badge.fury.io/js/%40homeofthings%2Fnode-utils)
[![Build Workflow](https://github.com/gms1/HomeOfThings/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/gms1/HomeOfThings/actions/workflows/build.yml)
[![Coverage Status](https://codecov.io/gh/gms1/HomeOfThings/branch/master/graph/badge.svg?flag=node-utils)](https://app.codecov.io/gh/gms1/HomeOfThings/tree/master/packages%2Fnode%2F%40homeofthings%2Fnode-utils)
[![DeepScan grade](https://deepscan.io/api/teams/439/projects/987/branches/1954/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=439&pid=987&bid=1954)
[![Known Vulnerabilities](https://snyk.io/test/github/gms1/HomeOfThings/badge.svg)](https://snyk.io/test/github/gms1/HomeOfThings)

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![License](https://img.shields.io/npm/l/@homeofthings/node-utils.svg?style=flat-square)](https://github.com/gms1/HomeOfThings/blob/master/packages/node/@homeofthings/node-utils/LICENSE)

# @homeofthings/node-utils

- `AsyncContext<T>`: little wrapper around `AsyncLocalStorage` providing default value

  ```Typescript
  asyncContext = new AsyncContext(defaultContext);
  ...
  asyncContext.set(newContext)
  ...
  currentContext = asyncContext.get();
  ```

- `ConfigService`: singleton service based on node-config

```Typescript
configService = new ConfigService({ configDirectory: 'path/to/config' });
```

then use one of the methods provided by the `ConfigService`:

```TypeScript
export declare class ConfigService {
  readonly configDirectory: string;
  readonly environment: string;

  constructor(_opts: ConfigOptions);

  getConfig(key: string): object | undefined;
  reloadConfig(): void;

  getString(key: string, defaultValue: string): string;
  getNumber(key: string, defaultValue: number): number;
  getBoolean(key: string, defaultValue: boolean): boolean;
  getObject(key: string, defaultValue: object): object;

  // resolve path relative to config-directory
  getPath(key: string, defaultValue: string): string;

  getOptionalString(key: string): string | undefined;
  getOptionalNumber(key: string): number | undefined;
  getOptionalBoolean(key: string): boolean | undefined;
  getOptionalObject(key: string): object | undefined;

  // resolve path relative to config-directory
  getOptionalPath(key: string): string | undefined;
}
```

reload on SIGHUP:

```TypeScript
process.on('SIGHUP', () => ConfigService.getInstance().reloadConfig());
```

- `LruCache<T>`: LRU cache

  ```Typescript
  cache = new LruCache<UserSession, number>(SESSION_CACHE_SIZE);

  cache.set(id, userSession); // add this to the cache and mark it as least recently used
  ...
  cache.get(anotherId); // if it is available in the cache it will be marked as least recently used
  ```

- `sequentialize`: run `Promises` in sequence

  ```Typescript
  await sequentialize(item.map(() => doWork(item)));
  ```

- `wait`: wait until a condition is true or timed out

  ```Typescript
  await wait(condition); // polls until condition is true
  await wait(condition, 1000); // polls until condition is true or timed out after 1000ms
  ```

- `WritableStrings`: a `Writable` for writing to a string array

- `quoteArgs` and `quoteArg`: quote arguments for better readability (e.g. for logging)

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