-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (38 loc) · 940 Bytes
/
app.js
File metadata and controls
43 lines (38 loc) · 940 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
32
33
34
35
36
37
38
39
40
41
42
43
// Import express
let express = require("express");
// Import Body parser
let bodyParser = require("body-parser");
// Import db
let db = require("./db/index.js");
// Import cors
let cors = require("cors");
// Initialise the app
let app = express();
// Import routes
let apiRoutes = require("./api-routes");
// Configure bodyparser to handle post requests
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(bodyParser.json());
// Configure cors
app.use(
cors({
origin: "http://localhost:3000",
})
);
// Connect to db
db.connect();
// Setup server port
var port = process.env.PORT || 8080;
// Send message for default URL
app.get("/", (req, res) => res.send("Hello World with Express"));
// Use Api routes in the App
app.use("/api", apiRoutes);
// Launch app to listen to specified port
app.listen(port, function () {
console.log("Running Contact Management API on port " + port);
});
module.exports = app;