NPM was created for developers to be able to share JavaScript code that they have written. This way
any developer around the world can grab somebody else's code that may solve his or her problem.
This creates a great knowledge base of scripts that people can constantly update or improve and build
on top of. As a matter of fact,
it is very rare that an app or a Web site these days are built purely from scratch.
By using the collective intelligence we can grab pieces of code that are really good and build on top
of it to create our product.
For example using JavaScript you can write virtual reality applications but you don't have to figure
out everything yourself.
Someone out there already worked on being able to use JavaScript VR So you use that person's code to
start your project.
Lets talk about how NPM works.
NPM looks like this.
A Web site with a search bar kind of looks like Google but here you can search for what we call Packages
and these packages are located in the NPM Registry and this Registry keeps track of files that have
been submitted.
Anybody can submit these files that are called packages or modules and they contain two things;
A JavaScript file and a package.json file.
and the package.json file which you've never seen before is a metafile that describes
this package.
So you can see here that this NPM registry is just a registry of all these files of JavaScript that
other people have written.
And the idea is to have small JavaScript files that do one thing really really well so that other people
can use it.
You then compose or combine different pieces of code and different packages on your project to add functionality
and not have to rewrite something that has already been written by another person.
So as you can see here I have let's say a person that has just written a JavaScript file that is really
really useful.
Well they think that other people might be able to use it so they push it up to the NPM Registry and
by using the search bar over here somebody can find your package maybe they're looking to have a script file
that creates a list of arrays for people interested in cats.
Well then they are able to find this file and download it from NPM Registry onto their computer.
So let's talk about the benefits from this.
Well you get expertise from others, maybe you don't know everything,
maybe others are better than you at
this certain thing well you use that collective knowledge to use their code.
But there's also a downside to this.
Not all packages are good code.
Anybody can put up their file to NPM, and you're also adding more bytes to your project which makes your
project size even bigger.
If you got all these files down into your project, well, that's a lot of files and each one is going to
have to be sent from the server to the browser.
And as you know from previous sections we want to minimize the size of our project so we built fast
web apps and there is an art to finding good NPM packages and you will get used to it after a bit of
experience.
So don't worry.
Now you also see here that I have something called the yarn.
yarn still uses the NPM Registry but you might see it every once in a while just like NPM.
It's a tool to grab things from the NPM Registry.
We won't talk about it in this course but just keep in mind that both yarn and NPM are very very similar.
If you learn one then you know the other so don't be afraid if you hear of a project that uses yarn
instead of NPM. Now you can browse NPM and find things.
But there's usually three types of packages.
One is packages that you can use on the browser.
So on the Front End, so that is you can download JQuery from NPM.
You can download all sorts of scripts that help you with front end workflow.
The second type are ones that give you new commands that you can use on the command line and I'll show you
an example that later on in this section.
And finally the third type of NPM package is once that you can use on Node.js on the Back End.
And that might sound scary to you but don't worry when we get to the Node.js section, I'll show you some of the Node packages
that you can use, but it's pretty much the same thing as JavaScript.
As a matter of fact NPM stands for Node Package Manager.
It was initially built for node but it was so good and so popular that you can now use it for the Front End
as well.
But it's all the same thing.
It all works the same.
Like I said before they're just scripts that are
you're able to use that other people have written and we're going to be using them a lot in this course.
Now you might be asking yourself, why are we learning this.
and this course? I mean, is it really that important?
Yeah, actually there are three must do things.
Now when starting a project and you'll see it in every single project.
One is that -well, they have an HTML file,
CSS file or JavaScript file.
They may have -they might have multiple of these but all projects have those especially ones that are
web based.
You also have to have your project on github and use source control like Git. Nobody stores their own
project on their computer.
They always have it with source control.
And finally you manage dependencies which is packages that other people have written. With NPM using
package.json file.
So in this section we're going to be working on this and finishing up our set up of how a typical project
looks like and we know how to do the first two, right?
Now in the next two videos I'm going to show you how to start using NPM to download files and using
package.json to manage those files.
It is a critical part of a developer workflow. So I'll see you in the next one. byebye.