http.createServer((req, res)=>{
console.log(
chalk.red(req.url), req.headers )
switch(path.extname(req.url)){
case ".html":res.writeHead(200, {"Content-type":"text/html"}); fs.createReadStream(__dirname+"/index.html").pipe(res); break;
case "":res.writeHead(200, {"Content-type":"text/html"}); fs.createReadStream(__dirname+"/index.html").pipe(res); break;
case ".css":res.writeHead(200, {"Content-type":"text/css"});fs.createReadStream(__dirname+"/style.css").pipe(res); break;
case ".js": res.writeHead(200, {"Content-type":"text/javascript"});fs.createReadStream(__dirname+"/main.js").pipe(res); break;
default :res.writeHead(200, {"Content-type":'text/html; charset=utf-8'});res.end("<h1>404 Страница не найдена </h1>")
}
req.on('data', function(chunk) {
console.log(chunk.toString());
// fs.createReadStream(__dirname+"/package.json").pipe(res)
});
})