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

@martinpang/nestjs-config

v1.2.3

Published

nestjs easy config via node-config

Downloads

57

Readme

@martinpang/nestjs-config

Configure your Nest.js Applications with node-config lib,without configuration,just import and use,so easy and convenient.

This module is build on node-config,support nestjs DI system,very easy to use and same to config lib.

How to use

npm i @martinpang/nestjs-config
//or you can use yarn or pnpm
pnpm add @martinpang/nestjs-config

the config dir is default to node-config ,the workspace rootdir/config,and many times same to ${workspace}/config

The config file type is same to node-config lib,json,json5,yaml,yml,xml ,cson,ts and so on ,details:https://www.npmjs.com/package/config

//This is app.module.ts,and config path dirs in rootdir
//In this case,the config dirs are rootdir/config2,rootdir/config,rootdir/config3
//The config file name is same to config lib,such as default.EXT,development.EXT ...
//Note:path is based on rootdir,'./' means rootdir,config dir will join with rootdir
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from "@martinpang/nestjs-config"; //here

@Module({
  imports: [ConfigModule.forRoot({ path: ['config2', 'config', 'config3'] })],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

If you use default config dir,you can also...

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from "@martinpang/nestjs-config"; //here

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

So easy to use in providers:

//This is app.service.ts
import { Injectable } from '@nestjs/common';
import { ConfigService } from "@martinpang/nestjs-config"; //here

@Injectable()
export class AppService {
  //Inject via contructor,and use anywhere
  constructor(private configService: ConfigService) {}
  
  getHello(): string {
    console.log(this.configService.get('Your config vars key'));
    return 'Hello World!';
  }
}

To use different env config file

//start your nestjs app in package.json script,config will merge NODE_ENV.EXT and default.EXT
"start:dev": "cross-env NODE_ENV=development nest start --watch",
"start:prod":"cross-env NODE_ENV=production nest start",
//PS.You need cross-env lib or manually set NODE_ENV on your system.

The ConfigMoudle can be used in global scope.You just need import once and use anywhere.

License

Nest is MIT licensed.