1.0.4 • Published 3 years ago

@routeinc/node v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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.