Skip to content

Commit

Permalink
fix: use dotenv to initialise environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
alichherawalla committed May 27, 2022
1 parent ec8eae8 commit 1a69620
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions seeders/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const os = require('os');
const { Products } = require('models/products');
const { ReferencedOrders } = require('models/referencedOrders');
const { UnshardedOrders } = require('models/unshardedOrders');

const dotenv = require('dotenv');
const {
UnshardedReferencedOrders
} = require('models/unshardedReferencedOrders');
Expand Down Expand Up @@ -57,7 +57,9 @@ function createOrder(products, dontCreate, referenced) {
return model.create(order);
}
function connectToMongo() {
console.log('connecting to mongo');
const envName = process.env.ENVIRONMENT_NAME || 'local';
console.log('connecting to mongo', envName);
dotenv.config({ path: `.env.${envName}` });
return mongoose.connect(getMongoUri());
}
async function runSeeders(func) {
Expand Down
2 changes: 1 addition & 1 deletion server/utils/mongoConstants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function getMongoUri(ip, port) {
function getMongoUri() {
return `mongodb://${process.env.MONGO_BASE_URI}:${process.env.MONGO_PORT}/ecommerce?readPreference=secondary`;
}
module.exports = { getMongoUri };

0 comments on commit 1a69620

Please sign in to comment.