NovaFactory

NovaFactory is the entry point for creating a Nova application. It initializes the underlying Fastify instance, sets up core plugins, and returns the App instance.

NovaFactory.create()

Creates and returns a new Nova application instance.

main.ts TypeScript
import { NovaFactory } from '@abrahambass/nova';

const app = await NovaFactory.create(options?);

AppOptions

Property Type Default Required Description
logger boolean true Optional Enables or disables Fastify's built-in Pino logger.
openapi OpenAPIOptions See below Optional Configuration for OpenAPI / Swagger documentation.

OpenAPIOptions

Property Type Default Description
title string "API" Title shown in the Swagger UI.
version string "1.0.0" API version.
description string "API documentation" Description shown in the docs.
termsOfService string "" Terms of service URL.

App Instance Methods

Once you have the app instance, you can use the following methods:

app.includeController(controller)

Registers a controller class directly. The controller is bound to the DI container and its routes are registered.

Usage TypeScript
app.includeController(UserController);

app.include(module)

Registers a Module with the application. The module's controllers and services are registered automatically.

Usage TypeScript
app.include(AppModule);

app.register()

Returns the Di (dependency injection) container for directly registering services.

Usage TypeScript
const di = app.register();
di.singleton(UserService);

app.use(middleware)

Registers a global middleware that runs before every route handler.

Usage TypeScript
app.use(async (req, reply) => {
  console.log(`[${req.method}] ${req.url}`);
});

app.security(plugins)

Registers security plugins (CORS, Helmet, Rate Limit, etc.). Accepts a single plugin or an array.

Usage TypeScript
await app.security([
  Security.cors({ origin: 'https://myapp.com' }),
  Security.helmet(),
  Security.rateLimit({ max: 50 }),
]);

app.openAPI()

Registers the @fastify/swagger plugin for auto-generating OpenAPI specifications.

app.enableDocs()

Enables the Swagger UI at /docs route.

Usage TypeScript
await app.openAPI();
await app.enableDocs();
// Swagger UI available at http://localhost:3000/docs

app.listen(port)

Bootstraps the application and starts listening on the specified port.

Usage TypeScript
await app.listen(3000);

app.env

Access the Environment instance to check the current environment.

Usage TypeScript
if (app.env.isDevelopment()) {
  await app.enableDocs();
}

Full Example

src/main.ts TypeScript
import 'reflect-metadata';
import { NovaFactory, Security, Auth } from '@abrahambass/nova';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NovaFactory.create({
    logger: true,
    openapi: {
      title: 'My API',
      version: '2.0.0',
      description: 'My awesome API',
    },
  });

  // Security
  await app.security([
    Security.cors(),
    Security.helmet(),
    Security.compress(),
    Auth.jwt({ secret: 'super-secret-key' }),
  ]);

  // Swagger (only in development)
  if (app.env.isDevelopment()) {
    await app.openAPI();
    await app.enableDocs();
  }

  // Register modules
  app.include(AppModule);

  await app.listen(3000);
}

bootstrap();