Skip to main content

.env file

To set up the .env, follow these commands!

  1. Setup file!
# your terminal should be in your project folder (check pwd!)
# create .env file
touch .env

# download env npm package
npm i dotenv
  1. add dotenv to be used in our application

add this into server.js

server.js
// require dotenv config
require('dotenv').config();
  1. add your DATABASE_URL into your .env file your previously created
.env
DATABASE_URL=<database-url-here-without-any-quotes>

// DATABASE_URL=mongodb+srv://<your-username>:<your-password>@cluster0-oxpsb.azure.mongodb.net/<your-database-name>?retryWrites=true&w=majority