Log in to Your Atlas Account
Click on New Project
Give Project Name & Click next
Click on Create Project
Create Cluster
Click Create
Select M0 Cluster, Give Name Of your Cluster & Click on go to Advanced Configuration
Select Shared & Click on Create Cluster
Set Username and Password & Click Create User
Note copy the Password for the Future usage
Add IP address → Click add current IP address & Click Finish & Close
Connect To Cluster
Install dotenv
using npm
npm i dotenv
Import it to the script
// Import dotenv Module
require('dotenv').config();
Create a file named .env
in the root of the dir.
Create variables in the .env
file.
DBURL=mongodb+srv://pavankc005:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
PORT=4000
Using it in the script
// Assign Port Number to Server
const port = process.env.PORT || 4000;
app.listen(port, () => {
console.log(`Server running on port <http://localhost>:${port}`);
});
// Database URL
const dbURL = process.env.DBURL
Code
Code
Code