Skip to content

Commit

Permalink
used dotenv and moved the config.json data inside the .env file and c…
Browse files Browse the repository at this point in the history
…reated a example.env text
  • Loading branch information
1-ankush-1 committed Oct 2, 2023
1 parent e4a30a8 commit 2040e67
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions example.env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MONGODB_URL = mongodb://localhost:27017/course
SECRET_KEY = YOUR_SECRET_KEY_HERE
PORT = 3000
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.6",
"csurf": "^1.11.0",
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
"express": "^4.18.2",
"express-mongo-sanitize": "^2.2.0",
Expand All @@ -21,6 +22,7 @@
"version": "0.0.1",
"main": "src/app.js",
"scripts": {
"start": "node src/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand Down
6 changes: 4 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const rateLimit = require("express-rate-limit");
const csrf = require("csurf");
const cookieParser = require("cookie-parser");
const mongoSanitize = require("express-mongo-sanitize");
const dotenv = require("dotenv");
dotenv.config();

const courseModel = require("./db/courseDB");

Expand All @@ -37,7 +39,7 @@ const addCSRF = require("./middlewares/addCSRF");

// Connect to MongoDB using the configuration
mongoose
.connect(config.mongodb_uri, {
.connect(process.env.MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
Expand Down Expand Up @@ -84,7 +86,7 @@ app.use(cookieParser());
//app.use(csrf());
//app.use(addCSRF)
app.use(
session({ secret: config.secret_key, resave: false, saveUninitialized: true })
session({ secret: process.env.SECRET_KEY, resave: false, saveUninitialized: true })

Check warning

Code scanning / CodeQL

Clear text transmission of sensitive cookie Medium

Sensitive cookie sent without enforcing SSL encryption.
);
app.use(flash());
app.use(passport.initialize());
Expand Down

0 comments on commit 2040e67

Please sign in to comment.