You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This course is amazing so far and ive learned a very substancial amount, however i have came across one issue that i cannot seen to figure out. Im trying to serve static files like css, js, and a favicon image, but when i try and serve a .png image, it just shows up as a black square, or if referenced in the html dosent show up at all. I sent the image by doing the following:
The path is correct, no error occurs while reading the png file, and i even logged out "err" and "imgData", and they are indeed wht they should be , which is "null" and a buffer. But in the browser it dosent seem to have rendered properly. Dose anyone have a work around or know somthing that im missing?
The text was updated successfully, but these errors were encountered:
So if I were you, the first place I would be looking for is in my browser's dev tools. Under the source and pages (in chrome), I would make sure that the png file is really being received on the client-side. If you have an error there, a screenshot will help someone with providing more advice if you're not able to understand the problem yourself. If you don't see the file, then the file isn't being received on the client-side, so it's more than likely being sent incorrectly on the server-side.
If that's not the problem, more source code access will help in my case.
This course is amazing so far and ive learned a very substancial amount, however i have came across one issue that i cannot seen to figure out. Im trying to serve static files like css, js, and a favicon image, but when i try and serve a .png image, it just shows up as a black square, or if referenced in the html dosent show up at all. I sent the image by doing the following:
const http = require("http");
const fs = require("fs");
const server = http.createServer((req,res) => {
fs.readFile("imagePath",(err,imgData) => {
res.setHeader("Content-Type","image/png");
res.end(imgData);
})
});
server.listen(3000);
The path is correct, no error occurs while reading the png file, and i even logged out "err" and "imgData", and they are indeed wht they should be , which is "null" and a buffer. But in the browser it dosent seem to have rendered properly. Dose anyone have a work around or know somthing that im missing?
The text was updated successfully, but these errors were encountered: