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 🙏

© 2026 – Pkg Stats / Ryan Hefner

config-core-nest

v0.0.27

Published

Libreria para configuracion global Core para NestJS

Downloads

1,070

Readme

Config Core Nest

Librería para centralizar la configuración base de proyectos NestJS, proporcionando una configuración estándar para:

  • Swagger
  • Validación global
  • Manejo global de excepciones
  • Interceptor de respuestas
  • Configuración de variables de entorno
  • Configuración inicial del proyecto

Requisitos

  • Node.js 20+
  • NestJS 11+
  • TypeScript 5+

Instalación

Instalar la librería:

pnpm add config-core-nest

Instalar las dependencias requeridas por el proyecto:

pnpm add @nestjs/config compression picocolors
pnpm add -D @types/compression

Configuración del package.json

Agregar las siguientes propiedades obligatorias:

{
  "name": "nombre-del-proyecto",
  "system": "Nombre visible del sistema",
  "version": "0.0.1",
  "description": "Descripción del sistema",
  "author": "blade-liger",
  "contact": {
    "name": "Jose David Mamani Figueroa",
    "email": "[email protected]"
  }
}

Configuración de Prettier

.prettierrc

{
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all",
  "quoteProps": "as-needed",
  "bracketSpacing": true,
  "useTabs": false,
  "sortAttributes": false,
  "jsxBracketSameLine": false,
  "arrowParens": "always",
  "endOfLine": "auto",
  "vueIndentScriptAndStyle": true,
  "printWidth": 80
}

.prettierignore

package.json

Configuración ESLint

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin'],
  extends: [
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
  ],
  root: true,
  env: {
    node: true,
    jest: true,
  },
  ignorePatterns: ['.eslintrc.js'],
  rules: {
    '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/no-floating-promises': 'off',
    '@typescript-eslint/no-unsafe-argument': 'off',
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-var-requires': 'off',
    '@typescript-eslint/no-unsafe-assignment': 'off',
    '@typescript-eslint/no-require-imports': 'off',
    '@typescript-eslint/no-unsafe-member-access': 'off',
    '@typescript-eslint/no-unsafe-return': 'off',
    '@typescript-eslint/no-unsafe-call': 'off',
  },
};

Configuración de tsconfig.json

Agregar:

{
  "compilerOptions": {
    "types": ["node"]
  }
}

Icono del proyecto

Crear el siguiente directorio:

src/
 └── assets/
      └── images/
           └── favicon.ico

Configuración del nest-cli.json

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "assets": [
      {
        "include": "assets/**/*",
        "outDir": "dist/assets"
      }
    ],
    "watchAssets": true,
    "deleteOutDir": true
  }
}

Variables de entorno

Obligatorias:

ENV_PORT=3300
ENVIRONMENT=development
LIMIT_REQUESTS=50mb
CORS_ORIGIN=*

ENVIRONMENT

Solo admite:

development
production

Configuración configuration.ts

Crear:

src/config/configuration.ts
import { configurationNest } from 'config-core-nest';
import { join } from 'path';

export default () => {
  const packageJson = require(join(process.cwd(), 'package.json'));

  return {
    ...configurationNest(packageJson),

    anotherKey1: process.env.ANOTHER_KEY_1 ?? '',
    anotherKey2: process.env.ANOTHER_KEY_2 ?? '',
  };
};

Configuración AppModule

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core';

import configuration from './config/configuration';

import {
  GlobalExceptionFilter,
  ResponseInterceptor,
} from 'config-core-nest';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: [configuration],
    }),
  ],

  controllers: [AppController],

  providers: [
    AppService,

    {
      provide: APP_FILTER,
      useClass: GlobalExceptionFilter,
    },

    {
      provide: APP_INTERCEPTOR,
      useClass: ResponseInterceptor,
    },
  ],
})
export class AppModule {}

Configuración main.ts

import { RequestMethod, VersioningType } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';

import compression from 'compression';
import { json, urlencoded } from 'express';
import * as path from 'path';
import * as pc from 'picocolors';

import {
  configSwagger,
  GlobalValidationPipe,
} from 'config-core-nest';

import { AppModule } from './app.module';

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

  const configService = app.get(ConfigService);

  const packageJson = configService.get('packageJson');

  app.use(
    json({
      limit: configService.get('limitRequest'),
    }),
  );

  app.use(
    urlencoded({
      extended: true,
      limit: configService.get('limitRequest'),
    }),
  );

  app.use(compression());

  app.enableVersioning({
    type: VersioningType.URI,
  });

  app.setGlobalPrefix('api', {
    exclude: [
      {
        path: '/',
        method: RequestMethod.GET,
      },
    ],
  });

  app.useGlobalPipes(new GlobalValidationPipe());

  app.enableCors({
    origin: configService.get('enableCors'),
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
    credentials: true,
  });

  if (configService.get('environment') !== 'production') {
    configSwagger(
      app,
      packageJson,
      path.join(__dirname, 'assets', 'images', 'favicon.ico'),
    );
  }

  const port = configService.get<number>('port');

  await app.listen(port, '0.0.0.0');

  console.info(
    pc.blue(
      `🚀 ${packageJson.name} v${packageJson.version} iniciado correctamente en ${await app.getUrl()}/api`,
    ),
  );
}

bootstrap();

AppController

import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
  ) {}

  @Get()
  getPing() {
    return this.appService.getPing();
  }
}

AppService

import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class AppService {
  constructor(
    private readonly configService: ConfigService,
  ) {}

  getPing() {
    return {
      version: this.configService.get('packageJson').version,
      system: this.configService.get('packageJson').system,
      description: this.configService.get('packageJson').description,
    };
  }
}

Resultado esperado

Una vez iniciado el proyecto:

GET /

Respuesta:

{
  "version": "0.0.1",
  "system": "Nombre del sistema",
  "description": "Descripción del sistema"
}

Swagger disponible en:

http://localhost:3300/api

Características

  • Configuración centralizada para NestJS.
  • Swagger automático.
  • Validación global.
  • Manejo global de excepciones.
  • Interceptor de respuestas uniforme.
  • Configuración mediante variables de entorno.
  • Compatible con NestJS 11+.
  • Preparado para proyectos con arquitectura modular.