0

I want to create a pure node.js server and serve the requested file. But I don't know how to read the GET request to use it on an if else statement to serve the correct file.

Something like:

http.createServer(function(req,res){
      if(req==="thing.txt"){
      fs.readFile('thing.txt', function(err, data) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.write(data);
      res.end();
  });}else{}
  }).listen(8080);
NewToPi
  • 187
  • 2
  • 9

0 Answers0