Skip to content

Instantly share code, notes, and snippets.

@eighteyes
Forked from dtrce/mp3.js
Last active December 20, 2015 17:39
Show Gist options
  • Save eighteyes/6169928 to your computer and use it in GitHub Desktop.
Save eighteyes/6169928 to your computer and use it in GitHub Desktop.
Updated mp3 to use readStreams
var http = require('http'),
fs = require('fs'),
path = require('path')
util = require('util');
http.createServer(function(req, res) {
var filePath = 'path_to_file.mp3';
var stat = fs.statSync(filePath);
res.writeHead(200, {
"Content-Type": "audio/mpeg",
'Content-Length': stat.size
});
var readStream = fs.createReadStream(filePath);
readStream.pipe(res);
})
.listen(2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment