Skip to content

Instantly share code, notes, and snippets.

@npow
Created June 9, 2012 19:10
Show Gist options
  • Save npow/2902211 to your computer and use it in GitHub Desktop.
Save npow/2902211 to your computer and use it in GitHub Desktop.
NodeJS return image
var http = require('http')
, fs = require('fs');
fs.readFile('image.jpg', function(err, data) {
if (err) throw err; // Fail if the file can't be read.
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.end(data); // Send the file data to the browser.
}).listen(8124);
console.log('Server running at http://localhost:8124/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment