New:Socket for Asana Is Now Available.Learn more
Get Started

@edirect/config

Package Overview
Dependencies
Maintainers
29
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edirect/config

npmnpm
Version
11.0.64
Version published
Weekly downloads
1.2K
379.03%
Maintainers
29
Weekly downloads
 
Created
Source

@edirect/config

Global NestJS configuration module for eDirect applications. Provides environment variable loading via dotenv and a ConfigService for accessing configuration values across the application.

Features

  • Loads .{NODE_ENV}.env file automatically on startup (e.g., .development.env, .production.env)
  • Global module — register once, inject ConfigService anywhere
  • Simple get(key) / getConfig() API
  • Dual injection tokens: class token (ConfigService) and string constant (CONFIG_SERVICE_TOKEN)

Installation

pnpm add @edirect/config
# or
npm install @edirect/config

Usage

Register in your AppModule

import { Module } from '@nestjs/common';
import { ConfigModule } from '@edirect/config';

@Module({
  imports: [ConfigModule],
})
export class AppModule {}

Because ConfigModule is decorated with @Global(), you only need to import it once at the root module. ConfigService will be available for injection in all feature modules automatically.

Inject ConfigService

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

@Injectable()
export class MyService {
  constructor(private readonly config: ConfigService) {}

  doSomething() {
    const dbUrl = this.config.get('DATABASE_URL');
    const port = this.config.get('PORT') ?? '3000';
  }
}

API

ConfigService

MethodSignatureDescription
constructor(filePath?: string)Optionally pass a .env file path. Automatically called with .{NODE_ENV}.env by the module.
get(key: string): string | undefinedReturns the value for the given environment variable key from process.env.
getConfig(): IStringMapperReturns all environment variables as a Record<string, string>.

CONFIG_SERVICE_TOKEN

An alternative injection token (string constant) for ConfigService. Useful when you need to inject by token rather than by class:

import { Inject } from '@nestjs/common';
import { CONFIG_SERVICE_TOKEN, ConfigService } from '@edirect/config';

constructor(@Inject(CONFIG_SERVICE_TOKEN) private config: ConfigService) {}

Environment File Convention

The module automatically loads .{NODE_ENV}.env from the working directory:

NODE_ENVFile loaded
development (default).development.env
staging.staging.env
production.production.env
test.test.env

Example .development.env:

PORT=3000
DATABASE_URL=mongodb://localhost:27017/mydb
REDIS_URL=redis://localhost:6379
LOGS_LEVEL=debug

Note: Never commit .env files containing sensitive credentials to version control.

Exports

export { ConfigModule } from './config/config.module';
export { ConfigService } from './config/config.service';
export { CONFIG_SERVICE_TOKEN } from './config/config.constants';
export type { IStringMapper } from './config/config.interfaces';

FAQs

Package last updated on 20 Aug 2026

Related posts