Last active
December 28, 2015 19:59
-
-
Save westonplatter/7554264 to your computer and use it in GitHub Desktop.
stream MP3 with 19 lines of nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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