-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (21 loc) · 993 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
"use strict";
const express = require('express');
const path = require('path');
const importCsvFile = require('./toolkit/importCsvFile.js');
const app = express();
const staticFilesPath = path.join(__dirname, "public"); // Make our 'public' sub-directory accessible via HTTP.
const staticFilesMiddleWare = express.static(staticFilesPath);
app.use("/", staticFilesMiddleWare);
app.get("/rest/data", (request, response) => { // Set up a HTTP GET request handler that can serve data to our web app.
importCsvFile("./data/data.csv") // Load the CSV file from the server's file system.
.then(data => {
response.json(data); // Send the content of the CSV file (as JSON) to the web app.
})
.catch(err => {
console.error(err);
response.sendStatus(500); // Let the web app know that an error has occurred.
});
});
app.listen(3000, () => { // Start our web server!
console.log("Web server listening on port 3000!");
});