I am using nestjs for my nodejs project, and I want to load the .env
file from outside of the project.
Here is the directory structure
.env
services
/nodejs
/my-apis
/src
/main.ts
and in my main.ts
import * as dotenv from "dotenv";
dotenv.config({ path: `../../../../.env` });
console.log("process.env.PORT", process.env.PORT);
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix("/api");
await app.listen(process.env.PORT);
}
but it is not getting the values from .env
, what can be the issue?