Skip to content

Commit

Permalink
Migrate to db url
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr Stelmashchuk authored and Volodymyr Stelmashchuk committed Jun 14, 2024
1 parent f92f0f8 commit e422e65
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions database/db.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
require('dotenv').config();
const mongoose = require('mongoose');

const dbUser = process.env.DB_USER;
const dbPassword = encodeURIComponent(process.env.DB_PASSWORD);
const dbHost = process.env.DB_HOST;
const dbPort = process.env.DB_PORT;
const dbName = process.env.DB_NAME;

const uri = `mongodb://${dbUser}:${dbPassword}@${dbHost}:${dbPort}`;
const uri = process.env.DB_URL

mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
dbName: dbName,
useNewUrlParser: true,
useUnifiedTopology: true,
});

const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('We are connected to MongoDB!');
db.once('open', function () {
console.log('We are connected to MongoDB!');
});

module.exports = mongoose;

0 comments on commit e422e65

Please sign in to comment.