I'm trying to use environment variables in the ClientsModule as such:
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
@Module({
imports: [
TypeOrmModule.forFeature([Process]),
ClientsModule.register([
{
name: 'PROCESS_SERVICE',
transport: Transport.RMQ,
options: {
queue: process.env.RMQ_PRODUCER_QUEUE_NAME,
urls: [process.env.RMQ_PRODUCER_URL],
queueOptions: { durable: true },
},
},
]),
And I've also tried this:
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigService } from '@nestjs/config';
const configService = new ConfigService();
const rmqProcessUrl = configService.get<string>('RMQ_PRODUCER_URL');
const rmqProcessQueue = configService.get<string>('RMQ_PRODUCER_QUEUE');
@Module({
imports: [
TypeOrmModule.forFeature([Process]),
ClientsModule.register([
{
name: 'PROCESSES_SERVICE',
transport: Transport.RMQ,
options: {
queue: rmqProcessQueue,
urls: [rmqProcessUrl],
queueOptions: { durable: true },
},
},
]),
But in both occasions the following error appears:
TypeError: metatype is not a constructor
It works as intended when I use the values directly. I have also tried importing and using
export const rmqServiceName = process.env.RMQ_PRODUCER_QUEUE_NAME
and
export const rmqServiceName = process.env.RMQ_PRODUCER_URL
but that also results in the same error.
So how can I get access to the .env
variables in the @ClientsModule
?
Is there a workaround that I'm missing?