Last active
August 29, 2015 14:13
-
-
Save chrismytton/5f0ac2fd54e0d3872f0a to your computer and use it in GitHub Desktop.
Image which takes 6 seconds to load
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
/node_modules/ |
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
{ | |
"name": "slow-image", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"dependencies": { | |
"express": "^4.10.7" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC" | |
} |
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
var express = require('express'); | |
var fs = require('fs'); | |
var app = express(); | |
app.get('/', function(req, res, next) { | |
res.set('Content-Type', 'image/jpeg'); | |
var readStream = fs.createReadStream(__dirname + '/stephen-williams.jpeg'); | |
readStream.on('open', function () { | |
setTimeout(function() { | |
readStream.pipe(res); | |
}, 6000); | |
}); | |
readStream.on('error', function(err) { | |
res.end(err.message); | |
}); | |
}); | |
app.listen(process.env.PORT || 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment