-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (20 loc) · 789 Bytes
/
server.js
File metadata and controls
27 lines (20 loc) · 789 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
// Import required dependencies
const express = require('express');
const fileRoutes = require('./routes/files');
const connectDB = require('./config/db');
require('dotenv').config(); // Load environment variables from .env file
const path = require('path');
// Initialize Express application
const app = express();
// Serve static files (HTML, CSS, JS) from the public folder
app.use(express.static(path.join(__dirname, 'public')));
// Connect to MongoDB database
connectDB();
// Middleware to parse JSON request bodies
app.use(express.json());
// Mount file routes at /api/files endpoint
app.use('/api/files', fileRoutes);
// Start the server on the specified port
app.listen(process.env.PORT, () => {
console.log(`Server running on http://localhost:${process.env.PORT}`);
});