-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (24 loc) · 880 Bytes
/
index.js
File metadata and controls
33 lines (24 loc) · 880 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
31
32
33
import express from 'express';
import cors from 'cors';
import mongoose from 'mongoose';
import 'dotenv/config';
import { toJSON } from '@reis/mongoose-to-json';
import { userRouter } from './routes/user.js';
import { categoryRouter } from './routes/categories.js';
import { advertRouter } from './routes/advert.js';
import { vendorRouter } from './routes/vendor.js';
await mongoose.connect(process.env.MONGO_URI).then(() => console.log("Database connected successfully")).catch((error) => console.log("Error connecting to database", error));
const app = express();
const port = process.env.PORT ||
3000
app.use(express.json())
app.use(cors());
app.use(express.json());
app.use(userRouter);
app.use(categoryRouter);
app.use(advertRouter);
app.use(vendorRouter);
mongoose.plugin(toJSON);
app.listen(port, () => {
console.log(`App is listening on port ${port}`)
});