0
0
Node.jsframework~10 mins

Buffer to string conversion in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert a Buffer to a string using the default encoding.

Node.js
const buf = Buffer.from('hello');
const str = buf.[1]();
Drag options to blanks, or click blank then click option'
AtoArray
BtoBuffer
CtoJSON
DtoString
Attempts:
3 left
💡 Hint
Common Mistakes
Using toBuffer() which does not exist on Buffer instances.
Using toJSON() which returns a JSON object, not a string.
2fill in blank
medium

Complete the code to convert a Buffer to a string using 'utf8' encoding explicitly.

Node.js
const buf = Buffer.from('world');
const str = buf.toString('[1]');
Drag options to blanks, or click blank then click option'
Autf8
Bascii
Cbase64
Dhex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ascii' which can misinterpret some characters.
Using 'base64' which encodes binary data, not text.
3fill in blank
hard

Fix the error in the code to correctly convert the Buffer to a string.

Node.js
const buf = Buffer.from('test');
const str = buf.[1]('utf8');
Drag options to blanks, or click blank then click option'
Astringify
BtoStr
CtoString
Dconvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like toStr or convert.
Using JSON.stringify which does not convert Buffer to string.
4fill in blank
hard

Fill both blanks to convert a Buffer to a string using 'base64' encoding and assign it to a variable.

Node.js
const buf = Buffer.from('data');
const encoded = buf.[1]([2]);
Drag options to blanks, or click blank then click option'
AtoString
B'base64'
C'utf8'
DtoBase64
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method named toBase64 which does not exist.
Passing 'utf8' when base64 encoding is needed.
5fill in blank
hard

Fill all three blanks to convert a Buffer to a string with 'hex' encoding and store it in a variable named hexString.

Node.js
const buf = Buffer.from('example');
const [1] = buf.[2]([3]);
Drag options to blanks, or click blank then click option'
AhexString
BtoString
C'hex'
DbufferString
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names that don't match the task.
Using wrong method names or encodings.