nestjs-flex

1.0.0 • Public • Published

NestJS-Flex

NestJS-Flex is a modular library designed to enhance NestJS applications by providing a foundation for state management, performance optimization, and flexibility while seamlessly integrating with other tools. It brings to the NestJS ecosystem principles inspired by efficient development practices, ensuring scalable and maintainable applications.


Features

  • State Management: Effortlessly manage your application's state with a centralized service.
  • WebSocket Gateway: Enhance real-time communication with built-in WebSocket functionality.
  • Middleware Support: Apply cross-cutting concerns globally with the FlexibilityMiddleware.
  • Performance Monitoring: Measure request duration for better performance insights using the PerformanceInterceptor.
  • Modular Architecture: Easily integrate and extend NestJS-Flex across your projects.

Installation

Install the nestjs-flex package:

npm install nestjs-flex

Getting Started

Here's a quick example to get you started:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  console.log('Starting the application...');
  await app.listen(3000);
}
bootstrap();

Add the FlexModule to your application:

import { Module } from '@nestjs/common';
import { FlexModule } from 'nestjs-flex';

@Module({
  imports: [FlexModule],
})
export class AppModule {}

Example Usage

State Management

Use StateService to manage application state:

Set State:

POST /flex/state
Body: { "key": "exampleKey", "value": "exampleValue" }

Get State:

GET /flex/state?key=exampleKey
Response: { "key": "exampleKey", "value": "exampleValue" }

WebSocket Gateway

Send a WebSocket message and receive a response:

  • Example WebSocket Endpoint: ws://localhost:3000/ws
  • Message Response: Echo: {your_message}

Middleware and Interceptors

  • FlexibilityMiddleware: Logs requests and adds custom headers.
  • PerformanceInterceptor: Logs request durations to optimize performance.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Readme

Keywords

none

Package Sidebar

Install

npm i nestjs-flex

Weekly Downloads

5

Version

1.0.0

License

ISC

Unpacked Size

32.1 kB

Total Files

20

Last publish

Collaborators

  • madalynbartman