Node.js Read File from Server

Share:
Now, showing you how to create an HTTP non-blocking server and how to read a file of the non-blocking filesystem.

 var http = require('http');  
 var fs = require('fs');  
 http.createServer(function(request, response) {  
  response.writeHead(200);  
  fs.readFile('index.html', function(err, contents) {  
   response.write(contents);  
   response.end();  
  });  
 }).listen(8080);  

Generate Request

 curl http://localhost:8080  

No comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();

Ads