-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (22 loc) · 823 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
// @ts-check
const express = require('express');
const uploadRoutes = require('./routes/file-upload');
const mongoUploadRoutes = require('./routes/mongo-file-upload');
const { connectDB } = require('./utils/mongo_db');
const { initGridFS } = require('./utils/gridfs');
const path = require('path');
require('dotenv').config();
const UPLOADS_DIR = path.join(__dirname, 'uploads');
// Connect to mongo database
connectDB().then(() => {
initGridFS();
});
const app = express();
app.use('/api/v1/file', uploadRoutes);
app.use('/api/v1/file', mongoUploadRoutes);
// Middleware to serve static files from the uploads directory
app.use('/uploads', express.static(UPLOADS_DIR));
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port http://localhost:${PORT}/api/v1/file`);
});