-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (25 loc) · 1015 Bytes
/
server.js
File metadata and controls
29 lines (25 loc) · 1015 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
29
const log = require('fancy-log');
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const mongoose = require('mongoose');
const { MEDIA_DIR } = require('./consts');
log.info('———— Starting data fetcher Server! ————');
log.info('———— Connecting to MongoDB! ————');
mongoose.connect(process.env.MONGODB_URL, { useNewUrlParser: true });
log.info('———— Connected to MongoDB! ————');
log.info('———— Creating media directory! ————');
if (!fs.existsSync(path.join(__dirname, MEDIA_DIR))) {
fs.mkdirSync(path.join(__dirname, MEDIA_DIR));
}
fs.readdir(path.join(__dirname, MEDIA_DIR), (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(__dirname, MEDIA_DIR, file), err => {
if (err) throw err;
});
}
});
log.info('———— Created media directory! ————');
require('./Fetchers/index');
log.info('———— Data fetcher server started! ————');