Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a Simple Dynamic Site with Node.js HTTP Methods and Headers Dealing with the POST Body

Austin Tindle
Austin Tindle
8,821 Points

Where are we 'require'ing from?

I understand that when we require a local js file, it's being taken from our local project files. But when we require a something from the Node API, where is it coming from? Are they all included somewhere on the local filesystem when I installed node?

Yes! Exactly! They are a part of the node installation.

2 Answers

Austin Tindle
Austin Tindle
8,821 Points

According to Caleb, and after some further digging, the Node modules such as 'fs' are included in the initial installation.

using buffers I think from an international level we deffinitely don't use many foreign protocols like we should.

const buf = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
  buf[i] = i + 97; // 97 is ASCII a
}
buf.toString('ascii');
  // Returns: 'abcdefghijklmnopqrstuvwxyz'
buf.toString('ascii',0,5);
  // Returns: 'abcde'
buf.toString('utf8',0,5);
  // Returns: 'abcde'
buf.toString(undefined,0,5);
  // Returns: 'abcde', encoding defaults to 'utf8'