Skip to content

Instantly share code, notes, and snippets.

@yihyang
Created June 9, 2018 04:21
Show Gist options
  • Select an option

  • Save yihyang/f0168be4d41d03fe23520eed3f8615ae to your computer and use it in GitHub Desktop.

Select an option

Save yihyang/f0168be4d41d03fe23520eed3f8615ae to your computer and use it in GitHub Desktop.
Simple HTTP Server written in NodeJS with Response from JSON File
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 );
{
"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