-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 842 Bytes
/
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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
require("dotenv").config();
const port = process.env.PORT || 8000;
const productsRouters = require("./routes/products");
const fuelsRoute = require("./routes/fuels");
const typesRoute = require("./routes/types");
const notFoundRoute = require("./routes/error");
// Middleware
app.use(bodyParser.json());
// routes
app.use("/api/products", productsRouters);
app.use("/api/fuels", fuelsRoute);
app.use("/api/types", typesRoute);
app.use("*", notFoundRoute);
// connect to the DB
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
// listen to the request
app.listen(port, () => {
console.log(`Server is running on ${port}`);
});
})
.catch((err) => console.log(err));