Answers for "how can node js file be serve"

0

how can node js file be serve

var fs = require('fs'),
    http = require('http');

http.createServer(function (req, res) {
  fs.readFile(__dirname + req.url, function (err,data) {
    if (err) {
      res.writeHead(404);
      res.end(JSON.stringify(err));
      return;
    }
    res.writeHead(200);
    res.end(data);
  });
}).listen(8080);
Posted by: Guest on September-28-2020

Code answers related to "how can node js file be serve"

Code answers related to "Javascript"

Browse Popular Code Answers by Language