-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
28 lines (23 loc) · 735 Bytes
/
setup.js
File metadata and controls
28 lines (23 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import winston from "winston";
import url from "url";
import { MongoClient } from "mongodb";
import settings from "./lib/settings";
const mongodbConnection = settings.mongodbServerUrl;
const mongoPathName = url.parse(mongodbConnection).pathname;
const dbName = mongoPathName.substring(mongoPathName.lastIndexOf("/") + 1);
const CONNECT_OPTIONS = {
useNewUrlParser: true
};
(async () => {
let client = null;
let db = null;
try {
client = await MongoClient.connect(mongodbConnection, CONNECT_OPTIONS);
db = client.db(dbName);
winston.info(`Successfully connected to ${mongodbConnection}`);
} catch (e) {
winston.error(`MongoDB connection was failed. ${e.message}`);
return;
}
client.close();
})();