1var http = require('http'),
2 fileSystem = require('fs'),
3 path = require('path');
4
5http.createServer(function(request, response) {
6 var filePath = path.join(__dirname, 'myfile.mp3');
7 var stat = fileSystem.statSync(filePath);
8
9 response.writeHead(200, {
10 'Content-Type': 'audio/mpeg',
11 'Content-Length': stat.size
12 });
13
14 var readStream = fileSystem.createReadStream(filePath);
15 // We replaced all the event handlers with a simple call to readStream.pipe()
16 readStream.pipe(response);
17})
18.listen(2000);