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 trialAustin Tindle
8,821 PointsWhere 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?
2 Answers
Austin Tindle
8,821 PointsAccording to Caleb, and after some further digging, the Node modules such as 'fs' are included in the initial installation.
Thomas Katalenas
11,033 Pointsusing 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'
Caleb Frieze
29,582 PointsCaleb Frieze
29,582 PointsYes! Exactly! They are a part of the node installation.