var http = require('http')
var fs = require('fs')
var request = require('request')
http
.createServer(function (req,res) {
//如果是网络连接 边下载边pipe
request('https://avatar.csdn.net/E/6/D/1_chuan403082010.jpg?1516788720').pipe(res);
//第二种
//fs.createReadStream('logo.png').pipe(res)
//第一种
// fs.readFile('logo.png',function (err,data) {
// if (err) {
// res.end('file not exist')
// }
// else {
// res.writeHeader(200,{'Context-Type':'text/html'})
// res.end(data)
// }
// })
}).listen(8090)Nodejs 显示图片的几种方式
最新推荐文章于 2025-05-06 13:41:46 发布
本文介绍了一个使用Node.js创建简单HTTP服务器的例子,演示了如何通过HTTP模块接收请求,并使用fs模块读取本地文件或通过request模块获取远程资源。
1061

被折叠的 条评论
为什么被折叠?



