-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (26 loc) · 860 Bytes
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const scholarshipRoutes = require('./routes/scholarshipRoutes');
const app = express();
const port = process.env.PORT || 3000;
// Connect to MongoDB
mongoose.connect('mongodb://localhost/scholarship-finder', {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('Connected to MongoDB'))
.catch((error) => console.error('Error connecting to MongoDB:', error));
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static('public'));
// Routes
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
// Scholarship routes
app.use('/api/scholarships', scholarshipRoutes);
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});