Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions config/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import { config } from "dotenv";
import env from "dotenv";

config();
// config();

export const PORT = process.env.PORT;
export const dbUri = process.env.MONGO_CONNECTION_URL;
export const jwtSecret = process.env.JWT_SECRET;
// export const PORT = process.env.PORT;
// export const dbUri = process.env.MONGO_CONNECTION_URL;
// export const jwtSecret = process.env.JWT_SECRET;

class Config{
_config={}
constructor(){
env.config();
this._config={
PORT=process.env.PORT,
dbUri=process.env.MONGO_CONNECTION_URL,
jwtSecret=process.env.JWT_SECRET
}
}
get(key) {
const val = this._config[key] ?? null;

if (!val) {
throw new Error(`Config for key [${key}] not found`);
}

return val;
}
set(key, val) {
this._config[key] = val;
}
}

const config = new Config();

export default config;