I have an .env.development
file with the following variables
DB_NAME=db.sqlite
COOKIE_KEY=sdfjshdfjsf
For this I have created a setup-app.ts
file with the setupApp
function, where I defined a cookie keys
value:
import { ValidationPipe } from '@nestjs/common';
const cookieSession = require('cookie-session');
export const setupApp = (app: any) => {
app.use(
cookieSession({
keys: ['asdfasdf'],
}),
);
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
}),
);
};
How to properly access this .env variable (COOKIE_KEY=sdfjshdfjsf
) value within my setupApp
function? Later I want to upload my app to Heroku and also create this COOKIE_KEY
variable there. So it should also work later with Heroku.
I found a way in NestJS to do this via
keys: [this.configService.get('COOKIE_KEY')]
but this apparently requires a class
with a dependency injection in the constructor
and further complicated configurations. In my case I have only a function.