Pop-Code / nestjs-console

A nestjs module that provide a cli to your application.
https://www.npmjs.com/package/nestjs-console
MIT License
558 stars 26 forks source link

Process.env issue #640

Closed nayan2 closed 1 year ago

nayan2 commented 1 year ago

In my main module - which is CLIMODULE, I am adding ConfigModule, which is recommanded by nestJs. But when I am logging process.env inside it. I am getting. something unexpected. Unbale to unbale why?

The process.env should give me. the project local .env file varibales or OS environment varibale.

My Module ->

import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SeedService } from './seed.service';

@Module({
  imports: [
    ConfigModule.forRoot({
        load: [() => {
            console.log(process.env);
            return {}
        }],
        isGlobal: true
    }),
    ConsoleModule
  ],
  providers: [SeedService],
  exports: [SeedService],
})
export class CliModule {}

Any, idea how can I get the local 'environment' variables? OR from a local .env file.

baijii commented 1 year ago

Same here. I'm using dotenv for the config. As soon as I try to execute a console script, it errors at the first env variable it does not know.

// app.module.ts

import * as dotenv from 'dotenv'
import { Global, Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { ConsoleModule } from 'nestjs-console'

dotenv.config()

@Global()
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    ConsoleModule,
  ],
})
export class AppModule {}
Rmannn commented 1 year ago

Can you create a small reproduction repo so i can investigate this ?

nayan2 commented 1 year ago

Hei, thanks for the reply. But, the issue has been Fixed.