var http = require('http'),
url = require('url'),
fs = require('fs');
new http.Server( function (req, res) {
if (req.url === "/music") {
var files = ["1.mp3", "2.mp3"];
sendFile(files, res);
}
}).listen(1337);
function sendFile(files, res) {
file = fs.ReadStream(files);
file.pipe(res);
file.on("error", function (err){
res.statusCode = 500;
res.end("server error");
console.log(err);
});
file
.on("open", function () {
console.log("open");
})
.on("close", function () {
console.log("close");
});
res.on("close", function (){
file.destroy();
console.log("file destroy")
});
}
html, body