图像显示错误使用node.js和express.js

一旦我打开“本地主机:3000”,图像越来越下载到我的笔记本电脑,而不是显示在网页上,任何人都可以请帮我吗?

var express= require('express'); var fs = require('fs'); var app= express(); var imgpath= 'C:\Users\Rohit\Downloads\images.jpg'; app.get('/',function(req,res){ res.send(fs.readFileSync(imgpath)); }); app.listen(3000); console.log('listening'); 

你必须设置标题。

 app.get('/',function(req,res){ res.set('Content-Type', 'image/jpg');//Added line res.send(fs.readFileSync(imgpath)); }); 

你必须设置内容types

 res.type('jpg').send(fs.readFileSync(imgpath));