Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismytton/5f0ac2fd54e0d3872f0a to your computer and use it in GitHub Desktop.
Save chrismytton/5f0ac2fd54e0d3872f0a to your computer and use it in GitHub Desktop.
Image which takes 6 seconds to load
/node_modules/
{
"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"
}
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