-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (32 loc) · 1.13 KB
/
server.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
39
40
const express = require('express');
const path = require('path'); // Make sure to require the path module
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/quizApp', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
// Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
// Serve the static files
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get('/quiz', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'quiz.html'));
});
app.get('/login', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'login.html'));
});
app.get('/signup', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'signup.html'));
});
// Handle form submissions and other API requests here
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});