-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (32 loc) · 1.03 KB
/
app.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
const express = require("express");
const cors = require('cors');
var mongoose = require('mongoose')
var sellerRouter = require('./routes/seller');
var productRouter = require('./routes/product');
var userRouter = require('./routes/user');
var orderRouter = require('./routes/order');
const dotenv = require('dotenv');
dotenv.config();
// Init the server
const app = express()
app.use(express.json())
app.use(cors())
// Connecting to local DB
mongoose.connect(`mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@e-commerce-api.rjf05ji.mongodb.net/?retryWrites=true&w=majority`).then(() => {
console.log("Database Connected");
}).catch((err) => {
throw new Error(err);
});
// main root
app.get('/', (req, res, next) => {
res.status(200).json('Welcome to E-Commerce API')
})
//API's
app.use('/sellers', sellerRouter)
app.use('/products', productRouter)
app.use('/users', userRouter)
app.use('/orders', orderRouter)
app.use("*", function (req, res, next) {
res.status(404).json("Not Found")
})
module.exports = app