forked from Trisha-tech/OnlineBookSales
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (40 loc) · 1.29 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const express = require(`express`);
const app = express();
const PORT = 8080;
const dotenv = require(`dotenv`);
const mongoose = require('mongoose');
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const errorMiddleware = require("./middlewares/error.js");
dotenv.config({path : `.env`})
/*MONGODB CONNECTION START*/
const MONGO_URL = process.env.MONGO_URL ;
mongoose.connect(MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true
})
mongoose.connection.on('connected', () => {
console.log("Connected to MongoDB")
})
mongoose.connection.on('error', (err) => {
console.log("Error Connecting to Database", err)
})
/*MONGODB CONNECTION END*/
app.use(express.json());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
// Route Imports
const customer = require("./routes/customerRoutes.js");
const product = require("./routes/productRoutes.js");
const order = require("./routes/orderRoutes.js");
app.use("/customer", customer);
app.use("/product", product);
app.use("/order", order);
// Middleware for Errors
app.use(errorMiddleware);
app.get('/', (req, res) => {
res.send(`Welcome to Scizers Assignment !!! Made by Trisha Sahu`);
})
app.listen(PORT,()=>{
console.log(`Server is running on port ${PORT}`);
})