-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (29 loc) · 999 Bytes
/
index.js
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
30
31
32
33
34
35
36
37
38
const express = require('express');
const cors = require('cors');
require('dotenv').config();
const connect = require('./db_connect');
const fileRoutes = require('./routes/file');
const textRoute = require('./routes/text');
const status = require('./routes/status');
const { GridFSBucket } = require('mongodb');
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
(async () => {
try {
const db = await connect();
const bucket = new GridFSBucket(db, {
bucketName: 'uploads'
});
app.use('/files', fileRoutes(db, bucket));
app.use('/text', textRoute(db));
app.use('/server', status(db));
app.get("/", (req, res) => res.send("Working"));
app.listen(process.env.PORT, () => {
console.log(`server running on ${process.env.PORT}`);
});
} catch (error) {
console.error('Error connecting to db:', error);
}
})();