## **"Not in the root folder" scenario:**
> Create a .env file in the **root directory** of your project.
[To see links please register here]
[![enter image description here][1]][1]
One scenario for this error is to create [dotenv][2] `.env` file --**NOT**-- in the `root folder` (Under `/src` for example).
Than this code:
```
const url = `mongodb+srv://${process.env.DB_USER}:${
process.env.DB_USER_PASSWORD
}@${process.env.DB_CLUSTER}.mongodb.net`;
console.log(url)
```
output:
```
mongodb+srv://undefined:
[email protected]
```
So the `"undefined"` URL connection:
```
const client = new MongoClient(url);
```
Throw 3 warnings:
> (node:27240) UnhandledPromiseRejectionWarning: **Error: querySrv
> ENOTFOUND** _mongodb._tcp.undefined.mongodb.net
> at QueryReqWrap.onresolve [as oncomplete] (dns.js:207:19)
>(node:27240) UnhandledPromiseRejectionWarning: Unhandled promise
> rejection. This error originated either by throwing inside of an async
> function without a catch block, or by rejecting a promise which was
> not handled with .catch(). To terminate the node process on unhandled
> promise rejection, use the CLI flag `--unhandled-rejections=strict`
> (see
[To see links please register here]
).
> (rejection id: 1)
>(node:27240) [DEP0018] DeprecationWarning: Unhandled
> promise rejections are deprecated. In the future, promise rejections
> that are not handled will terminate the Node.js process with a
> non-zero exit code.
<hr>
**One more "close" scenario:**
`.env` in the root folder but the file is **empty**:
[![enter image description here][3]][3]
<hr>
### Solution
The **first step** to solve this issue is to `console.log(url)` and check if `process.env` returns the correct [Connection String][4].
<hr>
Related:
- **dotenv github readme**:
[To see links please register here]
- **Connect to a MongoDB Database Using Node.js
:**
[To see links please register here]
[1]:
[2]:
[To see links please register here]
[3]:
[4]:
[To see links please register here]