Skip to content
Advertisement

How to easily display Image from Node JS

I can’t find a simple solution how to display an image on my website. I can read it in my node js backend but it will download the file instead of placing in my img tag.

Do you have a simple solution for that? Thank you very much!

HTML

JavaScript

NODE JS

JavaScript

Advertisement

Answer

The problem you face here is not how you read the data, it’s how you send the data to Frontend.

First of all, you need to set the headers properly that the frontend (receiver) understands that it’s an image and doesn’t download that but to show it.

Modified your code here:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement