String Decoder

String decoder module in node.js is used to provide an API for decoding buffer object into strings. Also , this decoding is performed in a manner that UTF-8 and UTF-16 characters multibyte coding is preserved.

We can import the query string module in the following way :

const StringDecoder = require('string_decoder').StringDecoder;  

String decoder methods

stringDecoder.write(buffer) :

write() function is used to return the specified buffer as decoded string, We pass buffer as the argument in this method.

An example is given below :

var stringDecoder = require('string_decoder').StringDecoder;
var sd = new stringDecoder('utf8');
var bufferData = Buffer('data to be buffered');
// the buffered data
//  the decoded buffer  

stringDecoder.end([buffer]) :

end() function is used to returns any remaining input stored in the internal buffer as a string. Bytes representing incomplete UTF-8 and UTF-16 characters will be replaced with substitution characters appropriate for the character encoding.

const StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder('utf8');


About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Selenium Online Training : Our next online training course for Selenium with Java starts from 17th December 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn, then you can join the course by sending email to

or Register below

Join My Facebook Group
Join Group