import dotenv from "dotenv";
import path from 'path';
dotenv.config({
path: path.resolve(path.__dirname, `${process.env.NODE_ENV}.env`),
});
export default config = {
NODE_ENV: process.env.NODE_ENV || "development",
HOST: process.env.HOST || "localhost",
PORT: process.env.PORT || 3001,
};
When i try to make config.js file to work multiple .env files but i get this error.os : windows 10
CodePudding user response:
__dirname
is not located in the path
module so path.__dirname
is undefined.
You should use __dirname
.
CodePudding user response:
i solved with that:
import dotenv from "dotenv";
import path from 'path';
dotenv.config({
path: path.resolve(path.dirname("/"), `${process.env.NODE_ENV}.env`),
});
const config = {
NODE_ENV: process.env.NODE_ENV || "development",
HOST: process.env.HOST || "localhost",
PORT: process.env.PORT || 3001,
};
export default config;