#How to use environment variables in decorator?

3 messages · Page 1 of 1 (latest)

vernal helm
#

I want to pass a certain string stored in my .env file to an @EventPattern() method decorator.

I understand that I cannot use ConfigService there because @EventPatter(<in_this_place>) this is not available.

I tried using process.env but it also doesn't work. What is the way to achieve this?

feral crow
#

IF you really want to to use env variables inside decorators, then in the main.ts the very first lines must be

import { config } from 'dotenv';
config()

This is before all other imports as well. This will populate process.env for you

vernal helm
#

Thank you @feral crow