# @routeinc/node

> Core NodeJS modules for Route backends.

Latest version **1.0.4** (published 2020-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @routeinc/node
pnpm add @routeinc/node
yarn add @routeinc/node
bun add @routeinc/node
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-12-10 |
| First published | 2020-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 42.3 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Author | routeinc |
| Maintainers | mrgrotts |

## Links

- npm: https://www.npmjs.com/package/@routeinc/node
- npm.io page: https://npm.io/package/@routeinc/node

## Dependencies (7)

- [uuid](https://npm.io/package/uuid.md) ^8.3.1
- [colors](https://npm.io/package/colors.md) ^1.4.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [cookie-session](https://npm.io/package/cookie-session.md) ^1.4.0
- [express-validator](https://npm.io/package/express-validator.md) ^6.7.0
- [node-nats-streaming](https://npm.io/package/node-nats-streaming.md) ^0.3.2

## Recent versions

- 1.0.4 (latest) — 2020-12-10
- 1.0.3 — 2020-12-10
- 1.0.2 — 2020-12-10
- 1.0.1 — 2020-12-07
- 1.0.0 — 2020-12-04

## README

# Route 2.0 Nodes

## About This Package

This package was created for sharing core nodejs modules across services for the Route Platform.

### Dependencies

- colors
- cookie-session
- express
- express-validator
- jsonwebtoken
- node-nats-streaming
- uuid

### Developer Dependencies

- @babel/cli
- @babel/core
- @babel/preset-env
- copyfiles
- prettier
- rimraf

## Errors

Use the following Errors by their corresponding HTTP Status Codes:

- 400 (Bad Request) - BadRequestError
- 401 (Unauthorized) - AuthenticationError
- 403 (Forbidden) - AuthorizationError
- 404 (Not Found) - NotFoundError
- 409 (Conflict) - ResourceAlreadyExistsError
- 422 (Unprocessable Entity) - RequestValidationError
- 500 (Internal Server Error) - GeneralError
- 503 (Service Unavailable) - DatabaseConnectionError

The Unknown Error is returned by the Error Middleware when an Error occurs and is not an instance of a known Error type. This ensures that any internal backend server errors are not sent to the frontend.

## Events

Events were developed for use with NATS Streaming Server.

### Listeners

Pass a custom onMessage handler to the subscribe function to handle message parsing. Be sure to call `event.ack()` at the end of your handler to acknowledge the event for the NATS Streaming Server.

- @client: Stan, an instantiated node-nats-streaming service
- @group: String, typically process.env.APP_NAME
- @channel: String, of the convetion 'service:action' (such as 'user:created')
- @subscribe: (onMessage: onMessage) => void
- @onEvent: (event: EventData) => void
- @parse: (message: Message) => any
- @subscriptionOptions: SubscriptionOptions, usually best to use defaults
- @wait: Number, default is 5000ms

### Publishers

Publishers do not need much customization beyond the channel. Simply send through any data you'd like.

- @client: Stan, an instantiated node-nats-streaming service
- @channel: String, of the convetion 'service:action' (such as 'user:created')
- @publish: (data) => void

## Middleware

The following Express Middleware is available through this package:

- errors: All purpose Express Error Handler, see Errors for types
- isAuthenticated: Verify JSON Web Tokens
- isAuthorized: Access Control (ACL) -- INCOMPLETE
- isValid: Validate values passed to Express Validator
- NotFound: 404 Handler for Express Router (not for requested resources that cannot be found)
- responses: Express Handler for HTTP Responses

## Utils

### Launcher

A more fun than useful terminal message used when the server starts.

### Terminator

Server termination handler, for the most part using a standard NodeJS shutdown configuration. Shuts down NATS Streaming Server if one is running.

### Token

JSON Web Token creation, decoding and verification. Requires a valid secret found at process.env.JWT_SECRET.

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