Javascript 不会显示从节点js传输到浏览器的图像

Javascript 不会显示从节点js传输到浏览器的图像,javascript,node.js,Javascript,Node.js,我为登录页编写了一个小型服务器,它可以完全工作,但在从浏览器请求传输图像时会发生错误。你能告诉我是什么问题吗 Server.js const http = require('http'); const routing = require('./routing'); const fs = require('fs'); const server = http.Server((req, res) => { routing.define(req, res); }).listen(8000); 索

我为登录页编写了一个小型服务器,它可以完全工作,但在从浏览器请求传输图像时会发生错误。你能告诉我是什么问题吗

Server.js

const http = require('http');
const routing = require('./routing');
const fs = require('fs');
const server = http.Server((req, res) => {
routing.define(req, res);
}).listen(8000);
索引

const url = require('url');
const fs = require('fs');
const { request } = require('http');
const define = function(req, res) {
let File__Path = (__dirname + "/main/index.html");
fs.readFile(File__Path, 'utf-8', (err, html) => {
res.writeHead(200, {"Content-Type": "text/html"});
res.end(html);
})
const Url__Parsed = url.parse(req.url, true);
let Path = Url__Parsed.pathname;
if(/\./.test(Path)) {
if(/\.css$/gi.test(Path)) {
res.writeHead(200, {"Content-Type": "text/css"});
let Read__Stream = fs.createReadStream(__dirname + "/static/css" + Path);
Read__Stream.pipe(res);
console.log("The Css file has gone!");
return;
} else if (/\.img$/gi.test(Path)) {
res.writeHead(200, {"Content-Type": "image/img"});
let Read__Stream = fs.createReadStream(__dirname + "/static/img" + Path);
Read__Stream.pipe(res);
console.log("The Img picture is off!");
return;
} else if (/\.svg$/gi.test(Path)) {
res.writeHead(200, {"Content-Type": "image/svg"});
let Read__Stream = fs.createReadStream(__dirname + "/static/img" + Path);
Read__Stream.pipe(res);
console.log("The Svg picture is off!");
return; 
} else if (/\.jpeg$/gi.test(Path)) {
res.writeHead(200, {"Content-Type": "image/jpeg"});
let Read__Stream = fs.createReadStream(__dirname + "/static/img" + Path);
Read__Stream.pipe(res);
console.log("The Jpeg picture is off!");
return;
} else if (/\.jpg$/gi.test(Path)) { // The problem is here!!!
res.writeHead(200, {"Content-Type": "image/jpg"});
fs.createReadStream(__dirname + "/static/img/" + Path).pipe(res);
} else if (/\.png$/gi.test(Path)) {
res.writeHead(200, {"Content-Type": "image/png"});
let Read__Stream = fs.createReadStream(__dirname + "/static/img" + Path);
Read__Stream.pipe(res);
console.log("The Png picture is off!");
} else if (/\.js$/gi.test(Path)) {
res.writeHead(200, {"Content-Type": "application/javascript"});
let Read__Stream = fs.createReadStream(__dirname + "/static/js" + Path);
Read__Stream.pipe(res);
    return;
}
}
};
exports.define = define;
浏览器:


如果你能帮我解决问题,我将非常感激

您需要在主目录中显示更多代码和文件分布