FAQ: Node.js Essentials - The Buffer Module

This community-built FAQ covers the “The Buffer Module” exercise from the lesson “Node.js Essentials”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Node.js

FAQs on the exercise The Buffer Module

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

After executing this code

const buffer1 = Buffer.from('hello');
const buffer2 = Buffer.from('world');

const bufferArray = [buffer1, buffer2];
const bufferConcat = Buffer.concat(bufferArray);

const bufferString = Buffer.toString(bufferConcat);

console.log(bufferString);

I got this output from the terminal:

$ node buffer.js
function Buffer(arg, encodingOrOffset, length) {
  showFlaggedDeprecation();
  // Common case.
  if (typeof arg === 'number') {
    if (typeof encodingOrOffset === 'string') {
      throw new ERR_INVALID_ARG_TYPE('string', 'string', arg);
    }
    return Buffer.alloc(arg);
  }
  return Buffer.from(arg, encodingOrOffset, length);
}

Shouldn’t it be helloworld? And why did it output this?

Hey! I’ve just completed the exercise and your code just has a typo at the fourth checkpoint, it should be:

const bufferString = bufferConcat.toString();

instead of:

const bufferString = Buffer.toString(bufferConcat);

As what you want to do is translate the previously created bufferConcat to a string.
Good luck!

1 Like

Regarding this chapter on the Buffer module: I know this whole lesson is just supposed to cover some ‘essentials’ of Node without going too much in depth, but still, I found it fell short on explaining what would give everything in this exercise its sense: what’s a buffer, in what way it is relevant to Node.js and in what situation we would be brought to use the Buffer module. Like often, Codecademy does a good job of putting the cart before the horse by making us apply a bunch of methods while still leaving us clueless about when, where and why we should apply them…

The first sections of this page helped a bit, in case it can benefit someone else’s understanding: Node.js buffer: A complete guide - LogRocket Blog

1 Like

Now I understand. Thanks!

1 Like