Created
June 9, 2012 19:10
-
-
Save npow/2902211 to your computer and use it in GitHub Desktop.
NodeJS return image
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 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
http://stackoverflow.com/questions/9540978/nodejs-how-to-read-and-output-jpg-image