All right welcome back and this video we're finally going to talk about what the dash dash to save flag
means when we do NPM install.
I had initially intended for this to be at the end of the last video but because of time constraints
as I started recording this I realized that there was some more detail that we needed to talk about
and a few other components that I wanted to bring into the discussion and that it made sense for it
to be a standalone video.
So the objectives here are to use the dash dash save flag to install packages and understand what it
means.
Explain what the package that Jason filed does and then use another command.
NPM and knit to create a new package.
Let's start by talking about this file package Scott J song.
And to do that I'm going to open up a nice blog post on the blog of a company called Noj it too and
this post explains what the package that just on file is every single NPM package that we've used and
that we will use in the future has a file called package J song.
So I can show you that first if we look at our first express app and we look in the Express directory
there is a file called package that Jason and we're going to discuss Jason later on.
It stands for a javascript object notation.
It's just a data type is a way of formatting text in a file to represent structure.
And what this is is a file that contains all the meta data about this particular application or this
package express so it contains a description a name an author and then all the different contributors
who have added to it.
It also contains the license the get hub repository you are l the homepage so it can be used to search
for it and probably most importantly the dependencies.
These are all the packages that express relies on that it needs in order to work.
And there is quite a few of them as you can see here.
And this file will collect them all.
And also explains the versions that are needed.
So that's what the package that some file is it holds metadata relevant to a specific project and I'll
show you one more example.
This is actually the same package that Jason but this one is on get help.
It's on the Express repository.
So this is the Express code itself being hosted on get help.
And we have a package such a song and inside of that here's all the same data that we just saw.
But the reason I'm showing it to you is that you might notice that the node modules directory is actually
not included it's not on get help but it is included when we go and look at Express right here instead
of Express we have lib and node modules and then package stuff Jason and a few other things I don't
get how there's just lib and node modules.
It's nowhere to be found.
And that's for a very particular reason which is that when we're sharing code and packages and repositories
are big projects and they depend on 10 20 or even 100 other packages rather than uploading all of these
packages with the rest of our code we can just put them in the package store J song.
And then when someone installs Express and someone downloads this or fork's this repository it makes
their own copy.
And they want to use it.
They'll see what they need to install but they won't download all of the baggage that goes along with
this automatically.
Luckily there's also a really easy command to automatically install everything inside the package such
Esan under dependencies and we'll also see that later on I came up with a silly analogy to help explain
this idea of the pack.
Jaison and in particular the dependency section.
So imagine that you have a great recipe a great dish that you make and I want my friend in Denmark to
be able to replicate the meal that I can make here in California.
So one option would be for me to go buy all of the ingredients for him package them all up pre-measured
everything put it in Ziploc bags and then put everything in a big box add in some instructions on how
to cook them.
Throw in some instructions on how to cook the meal.
Tape it all up and then go to the post office and pay a lot of money to ship it to my friend in Denmark
.
The alternative is just to send my friend a letter.
And in that letter we'll just describe the ingredients and the quantities that are needed.
And then once that letter gets to Denmark my friend can figure out what he needs to buy what he already
has how much he needs everything and he can prepare the meal on his own.
Hopefully you can see where I'm going with this.
The way that the package that Jason works is that it's the recipe for the ingredients that are needed
for a specific package or library rather than sending the contents of all of these individual packages
.
We just send a package that Jason that is basically a shopping list for all the packages and whoever's
using that package can then easily go and install all of these sort of up all that up.
Peggy Stut Jaison contains a bunch of metadata about a particular application or package and that ranges
from things like the name of it the description of version number all the way down to the dependencies
which in my mind is the most important aspect.
It contains a list of packages and the version number of each package that's needed in order for this
application to run.
So that brings me to the next point which is what does a dash dash save do.
When we install a package with NPM install and we add on this flag at the end.
Dash dash save it will take the package name and version in automatically save it into our package JS
on file if we have one.
Oh quickly demonstrate that we are to make a new directory and I'm just going to call this package.
On demo and then CD into that.
And the first thing I need to do is create a package that JS on file and I can do that myself by doing
touch package that Jason and then filling out all those fields.
But there's an easier way which is this third little bullet point here using NPM and need to create
a package Duguay some for us.
So go down to my terminal and type NPM in it inside of the folder where I want my application to exist
in this case package based on demo.
I'll hit enter and I get this message printed out to me.
It says this utility will walk you through creating a package dot JSON file.
Basically it asks me a bunch of questions like what's the name of my package.
And then I type it in and then hit Enter when I'm done and we'll ask me another question and then we
use all that data to make our package that Jason at the very end.
So for name it's guessing that we want to call it package to chase on demo because that's the name of
the folder we're in.
Which is fine.
So we can just hit enter and it will use that.
Same thing with version if I just hit enter it will use version 1.0 0.00 does need to be in this format
of some number.
Another number another number description.
Well just do simple package that J some demo entry point refers to the file where application starts
and in most of our applications it's going to be apt.
Yes.
And that's just a personal preference in this case.
We're not really going to have an application at all.
We're just installing packages just to show you how it works.
So we can put whatever we want we'll hit enter from test command and get repository keywords as well
.
We're not going to enter any of that for author can put in cold steel license and just use the default
one and you can see it shows me a little preview of what it's going to do and then it.
Is that OK.
I'll get yes or enter.
And now if I type LS I have a new file package such a song.
So here's the package that Jason move it up here you can see it has our name and our version and everything
else that we did.
But it doesn't have any dependencies yet.
So now let's go and install a new package will do express.
So we just run NPM install express and then dash dash save at the end and hit enter.
And you see we now end up with a dependancies field here and it has.
EXPRESS And then our version 4.1 3.3.
And we can install another package like Cat me dash dash save and it adds that into Pakistan based on
under dependencies as well.
All right so let's wrap up the package.
Jason file contains metadata about an application order package.
It's really really common to see them and really common for us to create our own package that Jaison
using NPM in it for every single app we make from here on out every single real app.
That's not just a quick demonstration.
We'll be using NPM in it and creating a package that Jaison.
And the last important point is that we can use dash dash save when we're installing a package.
Doesn't matter what package any package we just add dash dash save at the end.
And that will install it and then also save it to the dependency section of our package that Jason along
with the version that we installed.
OK.
In the next video we're going to keep moving forward with Express