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);
}
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.
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.