# nucleodeti.utils

> Nucleo Express Utilities is a TypeScript module that provides helper classes and middlewares for common patterns when working with Express.js.

Latest version **1.2.7** (published 2024-02-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install nucleodeti.utils
pnpm add nucleodeti.utils
yarn add nucleodeti.utils
bun add nucleodeti.utils
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.7 |
| Published | 2024-02-04 |
| First published | 2024-01-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nucleodeti |

## Links

- npm: https://www.npmjs.com/package/nucleodeti.utils
- npm.io page: https://npm.io/package/nucleodeti.utils

## Dependencies (9)

- [mysql2](https://npm.io/package/mysql2.md) ^3.9.1
- [express](https://npm.io/package/express.md) ^4.18.2
- [request-ip](https://npm.io/package/request-ip.md) ^3.3.0
- [http-status](https://npm.io/package/http-status.md) ^1.7.3
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.21
- [class-validator](https://npm.io/package/class-validator.md) ^0.14.1
- [@types/request-ip](https://npm.io/package/@types/request-ip.md) ^0.0.41
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.5.1
- [rate-limiter-flexible](https://npm.io/package/rate-limiter-flexible.md) ^4.0.1

## Recent versions

- 1.2.7 (latest) — 2024-02-04
- 1.2.6 — 2024-02-04
- 1.2.5 — 2024-02-04
- 1.2.4 — 2024-02-04
- 1.2.3 — 2024-02-04
- 1.2.2 — 2024-02-02
- 1.2.1 — 2024-02-02
- 1.2.0 — 2024-01-30
- 1.1.9 — 2024-01-30
- 1.1.8 — 2024-01-30
- 1.1.7 — 2024-01-30
- 1.1.6 — 2024-01-30
- 1.1.5 — 2024-01-30
- 1.1.4 — 2024-01-30
- 1.1.3 — 2024-01-30
- … 14 more at https://npm.io/package/nucleodeti.utils/versions

## README

# Nucleo Express Utilities

Nucleo Express Utilities is a TypeScript module that provides helper classes and middlewares for common patterns when working with Express.js.

## Installation

```bash
npm install nucleodeti.utils
```

## Usage

### NucleoHelpers

The `NucleoHelpers` class provides helper methods for handling common response patterns.

#### `sendResponse(response, content)`

Sends a JSON response with the specified status, message, and optional content.

- `response`: The Express response object.
- `content`: An object containing status, message, and optional content.

Example:

`const nucleoHelpers = new NucleoHelpers();
nucleoHelpers.sendResponse(res, { status: 200, message: 'Success', content: { data: 'Some data' } });`

#### `sendErrorResponse(response, err)`

Sends a generic internal server error response.

- `response`: The Express response object.
- `err`: The error object.

Example:

`const nucleoHelpers = new NucleoHelpers();
nucleoHelpers.sendErrorResponse(res, new Error('Something went wrong'));`

### NucleoMiddlewares

The `NucleoMiddlewares` class contains common middleware functions.

#### `dtoValidator(dtoClass)`

Validates the request body against a specified Data Transfer Object (DTO).

- `dtoClass`: The class of the DTO to validate against.

Example:

`const nucleoMiddlewares = new NucleoMiddlewares();
app.post('/endpoint', nucleoMiddlewares.dtoValidator(MyDTO), (req, res) => {
  // Your route logic here
});`

## Contributing

Feel free to open issues and pull requests.

## License

This project is licensed under the MIT License - see the [LICENSE.md](https://chat.openai.com/c/LICENSE.md) file for details.

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