const http = require('http');
const fs = require('fs');
const hostname = '127.0.0.1';
const port = 1337;
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'image/png' });
fs.createReadStream('./image.png').pipe(res);
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
会报 Error: ENOENT: no such file or directory, open './image.png' image.png 在js 当前目录。 求问,导致报错的原因和改如何解决