-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (25 loc) · 737 Bytes
/
index.js
File metadata and controls
30 lines (25 loc) · 737 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
const express = require("express");
const app = express();
const path = require("path");
const fs = require("fs");
const student = require("./routes/students");
const bodyParser = require("body-parser");
const cors = require("cors");
require("dotenv/config");
const port = process.env.PORT || 3005;
// Middleware
app.use(cors());
app.use(bodyParser.json());
app.use("/students", student);
app.get("/", async (req, res) => {
res.sendFile(path.join(__dirname + "/index.html"));
});
// City Api
app.get("/city", async (req, res) => {
let cityData = fs.readFileSync("json/city.json");
res.send(JSON.parse(cityData));
});
// Start server
app.listen(port, () =>
console.log(`CORS-enabled web server listening on port ${port}`)
);