Node js convert image to base64 Example

Node js convert image to base64 Example

In this article, we will explain to you how to convert image to base64 string in node js(Node js convert image to base64 Example). sometimes we need to convert image file to base64 encoding.

If you want to convert an image file to base64 then you can there are two ways such as simple process and third-party npm package.

Node Js Application Setup

First, we will open the command prompt and create the application in our directory. for this, you can follow the below command.

Install NPM Package

After the done setup node js application, we will install the express npm package for routing. so you can see the following npm command.

Example 1

In this example, we will convert the image to a string using simple ways. so you can see the following example.
server.js

Example 2

In this example, we will encode image into base64 string using the node-base64-image npm module. so you can see the following example.

Run Node js Application

we will run the node js application using the below command. so you can follow the below command.

Now you can run the example using the below Url in the browser.

Please follow and like us: