npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aws-serverless-tools/nest

v1.0.0

Published

A collection of tools to make building and deploying AWS serverless Nest applications AWESOME.

Downloads

7

Readme

Nest AWS Serverless Tools

In alpha mode. Maybe pre-alpha. Docs coming soon.

Installation

If you did not use the init process from the @aws-serverless-tools/cli package, the tools package can be installed directly:

npm install --save @aws-serverless-tools/cli

AwsServerlessToolsModule

This module simplifies the following:

  1. Enabling an OpenAPI documentation web server side-by-side with your API (at /apidocs by default).
  2. Generating an OpenAPI specification file.
  3. Generating an Angular client module.

Setup

Module import

First, import the module into your AppModule.

// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AwsServerlessToolsModule } from 'nest-aws-serverless-tools';

@Module({
  imports: [
    AwsServerlessToolsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Once imported, update the main.ts file to retrieve the ApiGatewayOpenApi service and start the document server.

Generation - Option A: Always generate on bootstrap

With this approach, every build will update the OpenAPI specification file and generate an Angular client.

// main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ApiGatewayOpenApi } from 'nest-aws-serverless-tools';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const openApi = await app.get(ApiGatewayOpenApi)
    .setNestAppContext(app)
    .enableDocumentationWebServer();
  await openApi.generateOpenApiFile();
  await openApi.generateAngularClient();

  await app.listen(3000);
}
bootstrap();
Generation - Option B: Only generate when the --openapi-generate flag is used (i.e. in npm run openapi)

This is the recommended option. This will generate the OpenAPI specification file and Angular client but only when --openapi-generate is passed to the command.

// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ApiGatewayOpenApi } from 'nest-aws-serverless-tools';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const openApi = await app.get(ApiGatewayOpenApi)
    .setNestAppContext(app)
    .enableDocumentationWebServer();

  if (!(await openApi.handleGenerateCommand(true, true))) {
    await app.listen(3000);
  }
}
bootstrap();

Configuration

In package.json, there are the following configuration options pre-enabled:

{
  "openApi": {
    "filePath": "./cfn/openapi.yaml",
    "clientOutputFolderPath": "./angular-client/",
    "clientAdditionalProperties": "apiModulePrefix=KerryTest,fileNaming=kebab-case,stringEnums=true,taggedUnions=true"
  }
}
  • docsWebServerRoot: The root at which to run the OpenAPI webserver. Default: "apidocs".
  • filePath: The path to the OpenAPI specification file.
  • apiBaseUrl: The host or base URL to the API for the Angular client to use by default.
  • clientOutputFolderPath: The relative path to the Angular client output.;
  • clientModulePrefix: The prefix of the Angular module, i.e. ${clientModulePrefix}ApiModule.
  • clientAdditionalProperties: Additional Angular client generation configuration. See https://openapi-generator.tech/docs/generators/typescript-angular/ for more options.

CloudFormationLambdaParametersConfig

When running your Lambda in AWS, you'll likely environment variables for configuration. However, maintaining these variables in process.env can be cumbersome.

CloudFormationLambdaParametersConfig is a loader for the @nestjs/config package to look at your CloudFormation file, cross-reference your Lambda environment variables to a specified parameters file, and make them available via the nestjs/config ConfigService.

Note that since this uses @nestjs/config, you are free to use .env files or any other configuration you see fit for secrets or other configuration options not managed via parameters.

Setup

ConfigModule Import

Add the @nestjs/config ConfigModule to your AppModule imports.

// main.ts
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AwsServerlessToolsModule, CloudFormationLambdaParametersConfig } from 'nest-aws-serverless-tools';

@Module({
  imports: [
    AwsServerlessToolsModule,
    ConfigModule.forRoot({
      load: [CloudFormationLambdaParametersConfig],
      isGlobal: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Stay in touch

License

Nest is MIT licensed.