Skip to content

Commit 1a69620

Browse files
fix: use dotenv to initialise environment variables
1 parent ec8eae8 commit 1a69620

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

seeders/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const os = require('os');
55
const { Products } = require('models/products');
66
const { ReferencedOrders } = require('models/referencedOrders');
77
const { UnshardedOrders } = require('models/unshardedOrders');
8-
8+
const dotenv = require('dotenv');
99
const {
1010
UnshardedReferencedOrders
1111
} = require('models/unshardedReferencedOrders');
@@ -57,7 +57,9 @@ function createOrder(products, dontCreate, referenced) {
5757
return model.create(order);
5858
}
5959
function connectToMongo() {
60-
console.log('connecting to mongo');
60+
const envName = process.env.ENVIRONMENT_NAME || 'local';
61+
console.log('connecting to mongo', envName);
62+
dotenv.config({ path: `.env.${envName}` });
6163
return mongoose.connect(getMongoUri());
6264
}
6365
async function runSeeders(func) {

server/utils/mongoConstants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function getMongoUri(ip, port) {
1+
function getMongoUri() {
22
return `mongodb://${process.env.MONGO_BASE_URI}:${process.env.MONGO_PORT}/ecommerce?readPreference=secondary`;
33
}
44
module.exports = { getMongoUri };

0 commit comments

Comments
 (0)