Last active
September 14, 2022 22:20
-
-
Save andrewd-sysdig/83f83f0d80c9ee240303b158bc5731f5 to your computer and use it in GitHub Desktop.
Sample hello-world node application
This file contains 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 http = require('http'); | |
const fs = require('fs') | |
const hostname = '0.0.0.0'; | |
const port = 3000; | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200; | |
res.setHeader('Content-Type', 'text/plain'); | |
fs.readFile("./mydata.json", "utf8", (err, jsonString) => { | |
if (err) { | |
console.log("File read failed:", err); | |
const printme = "Hello World!" | |
res.end(printme) | |
} | |
const printme = jsonString | |
res.end(printme) | |
}); | |
}); | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment