Added .env variables

This commit is contained in:
hardcodder 2021-04-26 15:59:58 +05:30
parent 23758a1e9e
commit cf9549cb6c
4 changed files with 12 additions and 4 deletions

4
app.js
View File

@ -13,7 +13,7 @@ const cors = require('cors') ;
const app = express() ;
const MONGO_URI = `mongodb+srv://Cantilever:Cantilever@cluster0.dqxva.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`
const MONGO_URI = `mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0.dqxva.mongodb.net/${process.env.MONGO_DEFAULT_DATABASE}?retryWrites=true&w=majority`
app.use(cors()) ;
app.use(bodyparser.json()) ;
@ -86,7 +86,7 @@ app.use(adminRoute) ;
mongoose.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true }).
then(result => {
console.log('connected');
app.listen(5000) ;
app.listen(process.env.PORT || 5000) ;
})
.catch(err => {
console.log(err);

View File

@ -146,4 +146,4 @@ module.exports.getTierCourse = async (req , res , next) => {
error : "error"
})
}
}
}

7
nodemon.json Normal file
View File

@ -0,0 +1,7 @@
{
"env" : {
"MONGO_USER":"Cantilever",
"MONGO_PASSWORD" :"Cantilever" ,
"MONGO_DEFAULT_DATABASE" :"myFirstDatabase"
}
}

View File

@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"start:dev": "nodemon app.js"
"start:dev": "nodemon app.js" ,
"start" : "node app.js"
},
"author": "",
"license": "ISC",