Networking and Streams

Introducing through2

Networking and Streams

Check out a free preview of the full Networking and Streams course

The "Introducing through2" Lesson is part of the full, Networking and Streams course featured in this preview video. Here's what you'd learn in this lesson:

After installing through2 that allows the creation of streams quickly.

Preview
Close

Transcript from the "Introducing through2" Lesson

[00:00:00]
>> Through is not part of core, so you'll have to install it with NPM, see if the NPM install through2. Another nice trick to use with NPM, is if you do dash capital S or dash dash save, then that's going to, if you have ever package JSON, it will put all of these things that you install into the package JSON for you.

[00:00:19]
Which is really nice, if you are starting a project. Okay, so the other thing that I wanted to show and then I think we can break, so that people can play around with these a little bit, is to show you what this looks like with the newer core interface.

[00:00:39]
So, with core, you require stream dot transform and you can pass in an object that has a transform function. There's also a finish function, which corresponds to what should happen when the stream is done with, so I can copy loud dot js to core loud dot js and we can use the core module now instead of through2.

[00:01:07]
So required. So through2 becomes required stream that transform. And then our two upper function now has to instantiate the transform stream with new and pass in an object, that has transform in it. Another way of doing this would be to instead of requiring stream, to require the package readable stream from NPM.

[00:01:34]
And I think that's a little bit better most of the time, because of the versioning that you get, that I mentioned, but for now, we'll just do it this way. So now if I run this program, core loud and I will, provided some input, yeah, so it works just the same.

[00:01:52]
So I'm gonna add these to the git repo, and take a little bit of a break, so people can poke around with these, modify them, try to write them out. Okay.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now