Node JS Convert Image File to Base64 String Example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hey,

In this lesson you will learn node js convert image file to base64. you will learn node js convert base64 string to image. you can see node js image to base64 string convert. step by step explain how to convert image to base64 in node js.

I will give you simple solution with full lesson of how to convert image to base64 string in node js. let's see solution with lesson:

Solution:

var base64str = base64_encode('demo.png');

function base64_encode(file) {

return "data:image/gif;base64,"+fs.readFileSync(file, 'base64');

}

Example:

const express = require('express');

const fs = require('fs');

const app = express();

var base64str = base64_encode('demo.png');

console.log(base64str);

function base64_encode(file) {

return "data:image/gif;base64,"+fs.readFileSync(file, 'base64');

}

app.listen(3000);

thank you very much for following up with me.

Tags

Recent Posts

Related Posts