'Can't pull sqs queue name from .env file in nestjs
When pulling the queue name through .env file I get the following error on the console: Cannot read properties of undefined (reading 'meta').
How can I pass queue name from .env file to nestjs @SqsMessageHandler decorator?. I am using @ssut/nestjs-sqs library.
@SqsMessageHandler(process.env.QUEUE_NAME, false)
public async handleMessage(message: AWS.SQS.Message) {
console.log(message);
}
@SqsConsumerEventHandler(process.env.QUEUE_NAME,'processing_error',
)
public onProcessingError(error: Error, message: AWS.SQS.Message) {
// report errors here
console.error(error);
console.error(message);
}
Solution 1:[1]
The problem is that the process.env.QUEUE_NAME
is not available at the time you're using it. You'll need invoke dotenv
(or whatever package that read & parse the env file) by yourself if you want to use process.env.
like this.
Solution 2:[2]
imports: [
...
ConfigModule.forRoot({
envFilePath: '.env',
}),
],
You can add env file import like this in your Sqs module, which is the standard way of using .env files in a NestJS module.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Micael Levi |
Solution 2 | Tauseef Khan |