Created
May 4, 2021 12:05
-
-
Save ng-the-engineer/0d3f16725947dc184c8f452f044a8cf3 to your computer and use it in GitHub Desktop.
Code snippet of Tutorial Node api csv k8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const app = express(); | |
const port = 3001; | |
app.get("/skills", (req, res) => { | |
fs.readFile( | |
path.join(__dirname, "/skills.csv"), | |
{ encoding: "utf-8" }, | |
(err, file) => { | |
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(file); | |
} | |
); | |
}); | |
app.listen(port, () => { | |
console.log(`App is listening on port ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment