@nestjs-mod/fastify
TypeScript icon, indicating that this package has built-in type declarations

1.5.4 • Public • Published

@nestjs-mod/fastify

Application modules with Fastify adapter for NestJS-mod

NPM version monthly downloads Telegram bot

Installation

npm i --save fastify @nestjs/platform-fastify @nestjs-mod/fastify

Modules

Link Category Description
FastifyNestApplicationInitializer system Fastify NestJS application initializer.
FastifyNestApplicationListener system Fastify NestJS application listener.

Modules descriptions

FastifyNestApplicationInitializer

Fastify NestJS application initializer.

Use in NestJS-mod

Use without options.

import { bootstrapNestApplication } from '@nestjs-mod/common';
import { FastifyNestApplicationInitializer } from '@nestjs-mod/fastify';

bootstrapNestApplication({
  modules: {
    system: [FastifyNestApplicationInitializer.forRoot()],
  },
});

Example of register fastify plugin.

import { bootstrapNestApplication } from '@nestjs-mod/common';
import { FastifyNestApplicationInitializer } from '@nestjs-mod/fastify';
import * as fmp from 'fastify-multipart';

bootstrapNestApplication({
  modules: {
    system: [
      FastifyNestApplicationInitializer.forRoot({
        staticConfiguration: {
          wrapFastifyAdapter: (fastifyAdapter: FastifyAdapter) => {
            fastifyAdapter.register(fmp);
          },
        },
      }),
    ],
  },
});

Static configuration

Key Description Constraints Default Value
cors CORS options from CORS package optional - -
bodyParser Whether to use underlying platform body parser. optional - -
httpsOptions Set of configurable HTTPS options optional - -
rawBody Whether to register the raw request body on the request. Use req.rawBody. optional - -
defaultLogger Fastify logger for application optional - -
logger Specifies the logger to use. Pass false to turn off logging. optional - -
abortOnError Whether to abort the process on Error. By default, the process is exited. Pass false to override the default behavior. If false is passed, Nest will not exit the application and instead will rethrow the exception. @default true optional - -
bufferLogs If enabled, logs will be buffered until the "Logger#flush" method is called. @default false optional - -
autoFlushLogs If enabled, logs will be automatically flushed and buffer detached when application initialization process either completes or fails. @default true optional - -
preview Whether to run application in the preview mode. In the preview mode, providers/controllers are not instantiated & resolved. @default false optional - -
snapshot Whether to generate a serialized graph snapshot. @default false optional - -
forceCloseConnections Force close open HTTP connections. Useful if restarting your application hangs due to keep-alive connections in the HTTP adapter. optional true -
wrapFastifyAdapter Method for additional actions before listening optional - -

Back to Top


FastifyNestApplicationListener

Fastify NestJS application listener.

Use in NestJS-mod

Use with manual environments and custom configuration.

import { bootstrapNestApplication, isInfrastructureMode } from '@nestjs-mod/common';
import { FastifyNestApplicationInitializer, FastifyNestApplicationListener } from '@nestjs-mod/fastify';
import { Logger } from '@nestjs/common';

bootstrapNestApplication({
  modules: {
    system: [
      FastifyNestApplicationInitializer.forRoot(),
      FastifyNestApplicationListener.forRoot({
        staticEnvironments: { port: 3000 },
        staticConfiguration: {
          mode: isInfrastructureMode() ? 'silent' : 'listen',
          preListen: async ({ app }) => {
            if (app) {
              app.setGlobalPrefix('api');
            }
          },
          postListen: async ({ current }) => {
            Logger.log(
              `🚀 Application is running on: http://${current.staticEnvironments?.hostname || 'localhost'}:${
                current.staticEnvironments?.port
              }/api`
            );
          },
        },
      }),
    ],
  },
});

Static environments

Key Description Sources Constraints Default Value
port The port on which to run the server. obj['port'], process.env['PORT'] optional 3000 3000
hostname Hostname on which to listen for incoming packets. obj['hostname'], process.env['HOSTNAME'] optional 0.0.0.0 0.0.0.0

Static configuration

Key Description Constraints Default Value
mode Mode of start application: init - for run NestJS life cycle, listen - for full start NestJS application optional listen -
preListen Method for additional actions before listening optional - -
postListen Method for additional actions after listening optional - -
defaultLogger Fastify logger for application optional - -
enableShutdownHooks Enable shutdown hooks optional true -
globalPrefix Global prefix optional api -
autoCloseTimeoutInInfrastructureMode Timeout seconds for automatically closes the application in infrastructure mode if the application does not close itself (zero - disable) optional - -
logApplicationStart Log application start optional true -

Back to Top

Links

License

MIT

Package Sidebar

Install

npm i @nestjs-mod/fastify

Weekly Downloads

11

Version

1.5.4

License

MIT

Unpacked Size

59.6 kB

Total Files

14

Last publish

Collaborators

  • endykaufman