Created
June 9, 2018 04:21
-
-
Save yihyang/f0168be4d41d03fe23520eed3f8615ae to your computer and use it in GitHub Desktop.
Simple HTTP Server written in NodeJS with Response from JSON File
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
| var http = require('http'); | |
| var fs = require('fs'); | |
| var port = "8080" ; | |
| http.createServer(function(request, response) { | |
| response.writeHead(200, { | |
| 'Content-Type': 'text/json', | |
| 'Access-Control-Allow-Origin': '*', | |
| 'X-Powered-By':'nodejs' | |
| }); | |
| fs.readFile('response.json', function(err, content){ | |
| response.write(content); | |
| response.end(); | |
| }); | |
| }).listen(port); | |
| console.log("Listening on port " + port ); |
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
| { | |
| "message": "This is a test server", | |
| "results": ["this", "is", "a", "test", "server"] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment