Do I need to upload the .env file?

Tell us what’s happening:
Hello everbody. I’m asking for help because when I finished this module, I didn’t pass the third task. I’m working locally and I uploaded the application to heroku. I think the problem might be because I do not include the .env file when I upload it to the server.

I am not sure if I have to upload it because for me, it would be similar to hardcoding.

And if I have to, could anyone explain me how exactly it is more secure to use this file ? thank you.

Your project link(s)

solution: https://frecc-mongo.herokuapp.com

here is my code:

require('dotenv').config();

var mongoose = require('mongoose');

mongoose.connect(process.env.MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});

let Person;

const createAndSavePerson = (done) => {

done(null /*, data*/);

};

const createManyPeople = (arrayOfPeople, done) => {

done(null /*, data*/);

};

const findPeopleByName = (personName, done) => {

done(null /*, data*/);

};

const findOneByFood = (food, done) => {

done(null /*, data*/);

};

const findPersonById = (personId, done) => {

done(null /*, data*/);

};

const findEditThenSave = (personId, done) => {

const foodToAdd = "hamburger";

done(null /*, data*/);

};

const findAndUpdate = (personName, done) => {

const ageToSet = 20;

done(null /*, data*/);

};

const removeById = (personId, done) => {

done(null /*, data*/);

};

const removeManyPeople = (done) => {

const nameToRemove = "Mary";

done(null /*, data*/);

};

const queryChain = (done) => {

const foodToSearch = "burrito";

done(null /*, data*/);

};

/** **Well Done !!**

/* You completed these challenges, let's go celebrate !

*/

//----- **DO NOT EDIT BELOW THIS LINE** ----------------------------------

exports.PersonModel = Person;

exports.createAndSavePerson = createAndSavePerson;

exports.findPeopleByName = findPeopleByName;

exports.findOneByFood = findOneByFood;

exports.findPersonById = findPersonById;

exports.findEditThenSave = findEditThenSave;

exports.findAndUpdate = findAndUpdate;

exports.createManyPeople = createManyPeople;

exports.removeById = removeById;

exports.removeManyPeople = removeManyPeople;

exports.queryChain = queryChain;

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0.

Challenge: Install and Set Up Mongoose

Link to the challenge:

Welcome there,

Remember, the .env file holds environment variables, which are also known as SECRETS. In your Heroku app dashboard, you should see the option to add environment variables/secrets. You can add it there - same principle.

You should never upload your database URI to GitHub, because then anyone can use/abuse your database and account.

If you are still a bit lost, I recommend searching the interweb for guides/tutorials/articles about environment variables.

Hope this clarifies.

Thank you so much. I am also starting with heroku and I didn’t know about that option. Now it makes more sense.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.