Skip to content

Commit

Permalink
create pub delete pub get pubs
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelsalemdev committed Feb 19, 2023
0 parents commit 1f1a455
Show file tree
Hide file tree
Showing 28 changed files with 8,060 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 6 additions & 0 deletions config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE=mongodb+srv://bilel_salem:Ycm2DYC8YjiZeezS@cluster0.udmqyu3.mongodb.net/restApiTutorial?retryWrites=true&w=majority
JWT_SECRET=AZERTYUIOP1234567890-bilel-salem
JWT_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=90
PORT=3000
NODE_ENV=development
43 changes: 43 additions & 0 deletions config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import path from "path";
import dotenv from "dotenv";
dotenv.config({ path: path.resolve(__dirname, "../config.env") });
interface ENV {
NODE_ENV: string | undefined;
DATABASE: string | undefined;
PORT: number | undefined;

JWT_SECRET: string | undefined;
JWT_EXPIRES_IN: string | undefined;
JWT_COOKIE_EXPIRES_IN: string | undefined;
}
interface Config {
NODE_ENV: string;
DATABASE: string;
PORT: number;

JWT_SECRET: string;
JWT_EXPIRES_IN: string;
JWT_COOKIE_EXPIRES_IN: string;
}
const getConfig = (): ENV => {
return {
NODE_ENV: process.env.NODE_ENV,
DATABASE: process.env.DATABASE,

JWT_SECRET: process.env.JWT_SECRET,
JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN,
PORT: process.env.PORT ? Number(process.env.PORT) : undefined,
JWT_COOKIE_EXPIRES_IN: process.env.JWT_COOKIE_EXPIRES_IN,
};
};
const getSanitzedConfig = (config: ENV): Config => {
for (const [key, value] of Object.entries(config)) {
if (value === undefined) {
throw new Error(`Missing key ${key} in config.env`);
}
}
return config as Config;
};
const config = getConfig();
const sanitizedConfig = getSanitzedConfig(config);
export default sanitizedConfig;
6 changes: 6 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["."],
"ext": ".ts,.js,.yaml",
"ignore": [],
"exec": "ts-node-dev --respawn --transpile-only ./src/server.ts"
}
Loading

0 comments on commit 1f1a455

Please sign in to comment.