Node JS Convert Image File to Base64 String Example
Hey,
In this example, 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 example of how to convert image to base64 string in node js. let's see solution with example:
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);
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Multiple File Upload in Node JS using Multer Example
- Node js Express Multiple Image Upload using Multer Example
- File Upload in Node JS using Multer Example
- Node js Express Image Upload using Multer Example
- Four Reasons Why Node.js is your Server-side Hero
- How to Connect MySQL Database in Node JS?
- Laravel Authenticate User in NodeJS with Socket io using JWT
- How to Upgrade Node.js Version in Ubuntu?
- How to Use Foreach Object in Node.js?
- Laravel 5.2 chat message module using socket.io, redis, express and nodejs from from scratch.