Habilelabs-Logo
Blog

Encoding and decoding in communication process

August 2nd, 2016 . 1 minute read
Blog featured image

What is Encoding and Decoding: Definition

In this post, we will discuss encoding decoding for the communication process.

Many times in the node.js application we need to encode and decode some data like password, secret key or any other important credentials. For that, we can use btoa and atob libraries. It provides to methods btoa() and atob() respectively.

btoa(decoded_data) = encoded_data
atob(encoded_data) = decoded_data

btoa library:

It converts binary data to base64-encoded ASCII.Simply install btoa npm library.

npm install btoa
Then require btoa into the file.

var btoa = require(‘btoa’);

Here you go to encode data.
Example :

var btoa = require('btoa');

var encoded = btoa("Habilelabs");

console.log("Encoded String : "+encoded);

Output :

Encoded String : SGFiaWxlbGFicw==

atob library:

It converts base64-encoded ASCII data back to binary.Simply install btoa npm library.
npm install atob

Then require atob into the file.

var atob = require(‘atob’);

Here you go to decode data.
Example :

var atob = require('atob');

var encoded = atob("SGFiaWxlbGFicw==");

console.log("Decoded String : "+encoded);

Output :

Decoded String : Habilelabs

We can encode and decode data with these two libraries easily.

If you have any issue in this process then simply ask in comment box. We also provide best web app development services.

Hope you enjoy this post, so don’t forget to share with friends.

Encoding & Decoding

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Author: pulkit
Share: