Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Amarjha01 committed May 12, 2024
1 parent 29f3f17 commit b18862b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"version": "1.0.0",
"description": "Dummy university web site project.",
"main": "app.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},

"repository": {
"type": "git",
"url": "https://www.github.com/amarjha01"
},
"author": "amar",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"express": "^4.19.2",
"mongoose": "^8.3.3"
Expand Down
1 change: 1 addition & 0 deletions server/src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONGODB_URI=mongodb+srv://amarjha880:[email protected]/collegeDB
19 changes: 18 additions & 1 deletion server/src/db/conn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
// const mongoose = require('mongoose');
// mongoose.connect('mongodb://localhost:27017/collegeDB');

// const mongoose = require('mongoose');
// mongoose.connect('mongodb+srv://amarjha880:[email protected]/collegeDB', { useNewUrlParser: true, useUnifiedTopology: true });

// Require the dotenv package to load environment variables from .env file
require('dotenv').config();

const mongoose = require('mongoose');
mongoose.connect('mongodb+srv://amarjha880:[email protected]/collegeDB', { useNewUrlParser: true, useUnifiedTopology: true });

// Retrieve the MongoDB URI from environment variables
const dbURI = process.env.MONGODB_URI;

// Connect to MongoDB using the URI from environment variables
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log('Connected to MongoDB');
})
.catch((error) => {
console.error('Error connecting to MongoDB:', error);
});

//mongodb+srv://<username>:<password>@<cluster-host>/<database-name>?retryWrites=true&w=majority

0 comments on commit b18862b

Please sign in to comment.