nodejs读取并且展示图片

var http = require('http');

var url = require('url');

var router = require("./router");

http.createServer(function(request,response){
	
	response.writeHead(200,{'contet-Type':'text/html;charset=utf-8'});

	if(request.url!=='/favicon.ico'){
		var pathname = url.parse(request.url).pathname;
		pathname = pathname.replace(/\//,'');

		router[pathname](request,response);
	}
	
	console.log('主程序执行完毕');

}).listen(8000);

console.log('now Server port is 8000');
var fileimg = require('./fileimg');

module.exports= {
	readimage:function(req,res){
		fileimg.readimg('./img/1.jpg',res);
		console.log('读取图片完成');
	}

}
var fs = require('fs');

module.exports ={
	readimg:function(path,res){
		fs.readFile(path,'binary',function(err,filedata){
			if(err){
				console.log(err);
				return;
			}else{
				res.write(filedata,'binary');
				res.end();
			}
		});
	}
}

 

你可能感兴趣的:(nodejs)