-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (31 loc) · 1.02 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
// Import express
import express from "express";
//import the allRoutes function from our restRoute.js file
import allRoutes from "./src/route/restRoute.js";
//import mongoose
import mongoose from "mongoose";
import bodyParser from "body-parser";
const app = express();
// Setup the port for the server
const port = 4000;
//set connection between the API and mongoDB
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost/studentDB", {
//avoid errors
useNewUrlParser: true,
useUnifiedTopology: true,
});
//parse requests and make it redable for our API
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//call the allRoute function and send app which initializes express
allRoutes(app);
// When a get request is made to / or the default page
// display a message.
app.get("/", (req, res) =>
res.send(`Your node and express server is running on port: ${port}`)
);
//print a message to the cli
app.listen(port, () => {
console.log("restAPI is running on port: " + port);
});