Skip to content

Commit

Permalink
Feat: MongoDB 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
hamsterster committed Sep 11, 2023
1 parent 7b8a496 commit 11e3704
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node src/bin/www"
"start": "DEBUG=app:* node src/bin/www"
},
"dependencies": {
"aws-sdk": "^2.1452.0",
Expand Down
4 changes: 4 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require('dotenv').config();
const express = require('express');
const connectDB = require('./configs/database');

const app = express();

connectDB();

require('./loaders/express')(app);
require('./loaders/routes')(app);
require('./loaders/errorHandlers')(app);
Expand Down
17 changes: 17 additions & 0 deletions src/configs/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require('mongoose');
const debug = require('debug')('app:database');

const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
debug('MongoDB Connected');
} catch (error) {
debug('MongoDB Connection Failed');
process.exit(1);
}
};

module.exports = connectDB;

0 comments on commit 11e3704

Please sign in to comment.