Skip to content

Instantly share code, notes, and snippets.

@westonplatter
Last active December 28, 2015 19:59
Show Gist options
  • Select an option

  • Save westonplatter/7554264 to your computer and use it in GitHub Desktop.

Select an option

Save westonplatter/7554264 to your computer and use it in GitHub Desktop.
stream MP3 with 19 lines of nodejs
// adjusted from dtrce's example, https://gist.github.com/dtrce/1204243
var http = require('http'),
fileSystem = require('fs'),
path = require('path');
http.createServer(function(request, response) {
var filePath = 'Users/weston/visible/test.mp3';
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
readStream.pipe(response);
})
.listen(2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment