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

@mridang/nestjs-defaults

v2.0.2

Published

A set of sane default for the NestJS framework

Downloads

256

Readme

A set of opinionated defaults for the the NestJS framework.

[!NOTE] This plugin has only been is designed for use with the Express tranport. It also assumes that you are using Sentry and deploying this to AWS.

Here are some of the notable features of this library:

  • Enables the built-in validator at the application level, thus ensuring all endpoints are protected from receiving incorrect data. https://docs.nestjs.com/techniques/validation
  • Secures the application by using Helmet by setting the necessary HTTP response headers.
  • Configures the handlebars templating engine https://docs.nestjs.com/techniques/mvc
  • Configures the cookie-parsing middleware to make it easier to read and write cookies https://docs.nestjs.com/techniques/cookies
  • Enables CORS support https://docs.nestjs.com/security/cors
  • Enables network error logging so that client-side errors can be tracked https://web.dev/articles/network-error-logging
  • Wires up Sentry so that all exceptions are reported to Sentry https://docs.sentry.io/platforms/javascript/guides/node/
  • Configures the logger to write log messages using the Elastic Common Schema https://www.elastic.co/guide/en/ecs/current/index.html
  • Configures a exception handler that shows pretty error pages for all 4/5xx errors
  • Configures a robots.txt endpoint that disallows all crawling and indexing
  • Configures the serving of static assets https://docs.nestjs.com/recipes/serve-static
  • Configures a health-check endpoint like Terminus https://docs.nestjs.com/recipes/terminus
  • Exports a mechanism for using Preact for SSR

Installation

Install using NPM by using the following command

npm install --save-dev @mridang/nestjs-defaults

Usage

Wiring this library comprises of two parts - configuring the NestJS application and configuring the Express transport.

To correctly leverage this library, you must use both.

Importing the exported module

The library exposes a module that should be imported in the root module. Importing that module will configure all the necessary defaults. The module requires that you specify the name of an AWS Secrets Manager configuration.

import { Global, Module } from '@nestjs/common';
import { DefaultsModule } from '@mridang/nestjs-defaults';

@Global()
@Module({
  imports: [
    DefaultsModule.register({
      configName: 'shush',
    }),
  ],
})
export class AppModule {
  //
}

Configuring the NestJS application

The library also provides a configure convenience method that can be used for setting up the transport e.g. the Handlebars templating engine, support for parsing cookies, validation, etc.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ClsService } from 'nestjs-cls';
import { AsyncLocalStorage } from 'node:async_hooks';
import compression from 'compression';
import { BetterLogger, configure } from '@mridang/nestjs-defaults';

async function bootstrap() {
  const nestApp = await NestFactory.create<NestExpressApplication>(AppModule, {
    rawBody: true,
    logger: new BetterLogger(new ClsService(new AsyncLocalStorage())),
  });

  configure(nestApp, __dirname);
  nestApp.use(compression());
  await nestApp.init();
  await nestApp.listen(3000);
}

bootstrap();

Contributing

If you have suggestions for how this library could be improved, or want to report a bug, open an issue - I'd love all and any contributions.

License

Apache License 2.0 © 2024 Mridang Agarwalla