Question: I'm trying to deploy an app on heroku but i can't if i use dotenv. This code doesn't work:

```js
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true }, () => {
  console.log("Connected to db successfully");
});
```

But this does:

```js
mongoose.connect("mongodb+srv://test:test@cluster0.j0you.mongodb.net/ecommerce?retryWrites=true&w=majority", { useNewUrlParser: true }, () => {
  console.log("Connected to db successfully");
});
```

When i try to use dotenv heroku throws this error:

```
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.

```

Answer: 
I had to go to heroku dashboard> settings> config vars and then add the key as MONGO\_URI and the mongo url value that mongodb gave me
You need to make sure of two things

1. go to heroku dashboard> settings> config vars and then add the key as MONGO\_URI and the mongo url value that mongodb gave me... this info is in the .env file of your project. you might have with another name like DATA\_BASE\_MONGO just make sure to use that name and key in the config vars.
2. Heroku dynamically assigns your app a port, so you can't set the port to a fixed number. Heroku adds the port to the env, so you can pull it from there. Switch your listen to this: **.listen(process.env.PORT || 5000)**, probably yo have it like .listen(5000), just make sure to change it.
And thats`s it you will have your app running.