-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (26 loc) · 811 Bytes
/
index.js
File metadata and controls
31 lines (26 loc) · 811 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
import express from "express";
import mongoose from "mongoose";
import "dotenv/config";
import cors from "cors";
import cookieParser from "cookie-parser";
import { authRouter } from "./routers/auth_router.js";
import { productRouter } from "./routers/product_router.js";
const app = express();
const port = process.env.PORT || 8088;
const mongo_uri = process.env.MONGO_URI
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cookieParser());
app.use('/api/adverts', authRouter);
app.use('/api/adverts/products', productRouter);
mongoose.connect(mongo_uri)
.then(() => {
console.log("Database is connected");
app.listen(port, () => {
console.log(`Server is live on ${port}`);
});
})
.catch(() => {
console.log("Database not connected")
})