-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (29 loc) · 1011 Bytes
/
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
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const booksRoutes = require('./routes/books');
const userRoutes = require('./routes/users');
const adminRoutes = require('./routes/admin');
const transactionRoutes = require('./routes/transaction');
const cors = require('cors');
require('dotenv').config();
//added this code for the api to work properly
app.use(cors({
credentials: true,
}));
//
app.use(express.json());
app.use('/api/books', booksRoutes);
app.use('/api/users', userRoutes);
app.use('/api/admin', adminRoutes);
app.use('/api/transactions', transactionRoutes);
mongoose.connect(process.env.MONGO_URI)
.then(() => {
console.log('Connected to MongoDB');
app.listen(process.env.PORT, () => {
console.log(`Server is runniwng on port ${process.env.PORT}`);
});
})
.catch((error) => {
console.log('Error connecting to MongoDB', error.message);
})