trainingtrains Logo

91-9990449935

 0120-4256464

Node.js StringDecoder

The Node.js StringDecoder is used to decode buffer into string. It is similar to buffer.toString() but provides extra support to UTF.

You need to use require('string_decoder') to use StringDecoder module.

Node.js StringDecoder Methods

StringDecoder class has two methods only.

Method Description
decoder.write(buffer) It is used to return the decoded string.
decoder.end() It is used to return trailing bytes, if any left in the buffer.

Node.js StringDecoder Example

Let's see a simple example of Node.js StringDecoder.

File: stringdecoder_example1.js

Node.js stringdecoder example 1