Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Forked from dtrce/mp3.js
Last active July 30, 2016 22:06
Show Gist options
  • Save marcoslhc/8151740f10857c4817c0 to your computer and use it in GitHub Desktop.
Save marcoslhc/8151740f10857c4817c0 to your computer and use it in GitHub Desktop.
streaming mp3 using nodejs
var http = require('http'),
fileSystem = require('fs'),
path = require('path'),
util = require('util');
http.createServer(function(request, response) {
var filePath = request.url.split('').slice(1).join('');
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