-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (22 loc) · 686 Bytes
/
app.js
File metadata and controls
25 lines (22 loc) · 686 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
const express = require("express");
const app = express();
const fs = require("fs");
const path = require("path");
const port = 8080;
app.get("/data", (req, res) => {
console.log("/data is called, path = ", path.join(__dirname, "/data.csv"));
fs.readFile(
path.join(__dirname, "/data.csv"),
{ encoding: "utf-8" },
(err, f) => {
if (err) console.log(err);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "POST, GET");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.send(f);
}
);
});
app.listen(port, () => {
console.log(`App is listening on port ${port}`);
});