-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (23 loc) · 858 Bytes
/
index.js
File metadata and controls
30 lines (23 loc) · 858 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
28
29
30
import dotenv from 'dotenv';
import express from 'express';
import mongoose from 'mongoose';
import { createStudent, getAllStudents, updateStudent } from './controllers/StudentController.js'; // import the createStudent function from the StudentController.js file
import wishlistRouter from './routers/wishListRouter.js';
import { connectDatabase } from './db/client.js';
dotenv.config();
const app = express();
const port = 8000;
app.use(express.json());
app.use('/api', wishlistRouter);
app.get('/students', getAllStudents);
app.post('/students', createStudent);
app.put('/students/:id', updateStudent);
const startServer = async () => {
await connectDatabase();
app.listen(port, () => {
console.log(`Countries app listening on port ${port}`)
})
}
startServer().catch(error => {
console.log(error, 'failed to start server')
})