00:00Now that we've got everything set up and configured
00:03and ready to work with, this chapter is dedicated
00:06to NPM in it.
00:08We're gonna really get to know how to work with NPM,
00:11starting with understanding what it actually is.
00:14Throughout this chapter.
00:16We're gonna go step by step
00:17and learn how to use NPM to, first of all, we're gonna learn
00:21how to self update NPM, how to install
00:25and uninstall packages in the global and local scope.
00:29Now don't worry too much about what that means
00:31because by the end of this chapter,
00:33you're definitely gonna know what it means
00:35and know how to work with this.
00:38We're also gonna learn how to declare NPM packages
00:41with package JSO, which will enable us
00:44to create node JS applications
00:46or register our node applications with NPM.
00:51Last but not least, which one
00:53of the most important topics we're gonna learn about version
00:56controlling packages, literally learning the var synex
01:01and understand how it works.
01:03So by the end of this chapter,
01:04you're gonna have all the critical key components of knowing
01:07how to work with NPM, which is gonna super empower you
01:11as a developer when we go into know JS in
01:14the following chapter.
01:16So let's get started with the first topic.
01:19And really the first topic is what is NPM?
01:23NPM stands for?
01:24Node Package Manager
01:26and Node is for the core technology
01:28that programming language slash world,
01:30that our developer language, which is in JavaScript,
01:34that enables us to build packages
01:36and code that will work on a server.
01:38That Node package manager basically enables us to share
01:43and get content from other developers,
01:45other code syn snippets to integrate into our code.
01:48So instead of languages like PHP
01:51and other platforms that have most
01:53of the core functionalities, prebuilt, prepackaged into PHP,
01:57and then we would just use them contrary to that,
02:01the node package manager may enables you
02:04to have a very basic construct, a ba, very basic language,
02:07and then you would extend it by calling different elements,
02:11installing different elements very easily
02:13to add new features that all the developer community
02:16around the world are doing.
02:19So know it as a package manager.
02:20And when you think of a package manager,
02:22it is exactly the same way as Google Play
02:25or the Apple Store works
02:27where you install an application directly through Apple
02:31or Google, and then you could then get automatic updates
02:35or physically update different applications based on your
02:39choice without needing to go to 1,000,001 different places.
02:43Knowing that it's going through one venue, one place
02:46that is managing the repository
02:48of all the different applications.
02:50The same applies to NPM when it comes
02:53to node related content now.
02:56So it's basically a repository, as
02:58We said, for node packages,
03:00and it maintains version control.
03:02Making it easier for you to then say,
03:04I need a specific version of the application.
03:08That is, for example, when a new operating system updates
03:12for the iOS, then there's a new update to that application,
03:15but that application is not applicable,
03:17wouldn't work on an older device.
03:20So by letting you as a developer gain access
03:23to specific versions, you can make sure that you're working
03:26with a version that you know will work with your application
03:29and secure yourself from updates in the future
03:32by not updating it, for example, not updating
03:35and enabling you to keep the version
03:37that you know will work for your system.
03:39So that's really NPM.
03:41With that said, what we're gonna do in this lecture,
03:43we're gonna update our NPM version,
03:46and in the process we're gonna fix our permissions
03:48that will be broken when we're updating our NPM version.
03:53We're gonna install by the end of this lecture,
03:55the latest version of NPM.
03:57So there we go. Let's get started.
04:01The default version of NPM
04:03that is installed when you install node js
04:08NPM is not that up to date.
04:13It's up to date, but it's really relative
04:15to the latest stable version that was released of no js.
04:20But in reality, your package manager is best
04:23to be the latest version.
04:24It can be always, and once in a while you wanna make sure
04:28that you have the latest version
04:30and this lecture, that's exactly what we're gonna do.
04:33And to do that, the steps involved with
04:35that are just typing NPM install,
04:40NPM minus G.
04:42Now I wanna talk about this process here.
04:45NPM is the command that we're working with.
04:46It's our package manager.
04:48If you watch our Linux videos on the installation
04:52of node js on a Linux, you saw that we used on CentOS,
04:57a package manager that was called Yum.
05:00NPM is very similar to that.
05:02It works in similar syntax
05:04where we're basically asking from NPM to install something,
05:07what do we wanna install?
05:09Well, we wanna install NPM. Where do we wanna install it?
05:13We want to install it globally
05:16so everyone will have access to it.
05:18So no matter in what folder I'm at, I'll be able
05:21to use this latest version of NPM.
05:23This is not a version or a package
05:25that I want only stored locally.
05:27It's a package I want stored globally.
05:30In reality, I'm treating the installation of an update
05:33to NPM, like the installation of any package,
05:36as we're gonna see in the following lectures when we
05:39install packages.
05:41In this case, we wanna make sure
05:42that it's installed globally.
05:44Now, if I go ahead and I press enter, in my case,
05:47I didn't have the permission set and configured correctly.
05:51By default, when you install node js on macro PC for
05:55that matter, you might see this error.
05:58If you see this error, that means your permissions are not
06:00processed correctly, they're not configured correctly.
06:04I'm gonna go ahead and clear my view here,
06:06but what I want you to do now is type NPM config
06:12get prefix.
06:14Now the get prefix command is gonna go into our
06:17configuration file to find out
06:20where is our NPM located In this case,
06:24NPM is located in the user folder and the local folder.
06:28And that is true. If I go inside
06:30and I look here, I'll see that
06:31among other things I have installed for my local user here,
06:36for the, for users in general, really not only this user,
06:40you'll see that I have your bin, uh, I have Git,
06:42I have a lot of other things.
06:44And among those things, among those packages, the prefix
06:48before that is our n pm.
06:50So if I take a deeper look here
06:52and I actually go inside of my bin folder
06:56and I do a search inside of here,
06:58I'll see more a lot of other packages.
07:00And among those packages, I'm gonna see the node package
07:03and I'm gonna see my NPM.
07:06Now, really, NPM is the one that I'm most interested in.
07:09Now what I really want to do is I wanna go
07:13through my process letting sh making sure
07:17that I could change all the things that I really need
07:20to make sure that it's gonna work properly.
07:23Now, there's a few places where no JS works with.
07:26One is in the share folder if it exists in
07:29our case, here we go.
07:30We have a share folder.
07:32It ha it stores things inside of, excuse me,
07:37while it stores things inside of the share folder,
07:42it stores things inside of the bin folder, it store things
07:45inside of the folder lib.
07:47And in there it has its modules.
07:50So if I go inside here, I should, I'll be able to see
07:52beyond only having the things that are related
07:55to other applications.
07:57You'll see that node modules are in here as well,
08:00which is something that is used by NPM.
08:03If I go inside of the share folder, you'll see
08:06that there's other things beyond the the related things to
08:10node js and NPM.
08:13So really what I'm gonna go through this process,
08:15what I'm going to do is I'm gonna change permissions more
08:18or less in everything inside of our core bin folder.
08:21Outside of that, it's not, not only in our bin slash
08:26npm, but I actually, I want to change the whole bin folder.
08:29I want to change the whole share folder,
08:31and I wanna share the the folder of lib slash node modules.
08:36Now, if you don't wanna go through
08:37and make all of these changes, there's other ways
08:40of doing this and you could learn about how to do
08:43that in a document that I have attached to this chapter.
08:47In our case, what I'm going to do is I'm gonna go ahead
08:49and change the owners.
08:51'cause currently, by the way, if you take a look at
08:53who are the owners of these
08:54Folders, you'll see that root.
08:56Some of them are me, some of them are the Root,
08:59some of them are an admin.
09:00They're not all me.
09:01And what I really want is I wanna make sure
09:03that all the files that are associated with that are needed
09:07by NPM are mine, so I could then work with them on my own.
09:12So to be able to do that, I'm gonna go ahead
09:13and clear the the view again here,
09:15I'm gonna type your n I'm gonna type your pseudo
09:18'cause I want to access as the root,
09:20and I'm gonna change the owner of a recursively.
09:24I'm gonna change the o, the owner to who to myself.
09:27So I'm gonna type, who am I, which will make sure
09:29that it's gonna be whoever you are, whoever the user
09:32of that currently is.
09:34I'm gonna put a space and I'm gonna list out the folders
09:36that I want to have changed.
09:38In this case, the folder that I want is the folder
09:41that we got from NPM Config Get Prefix.
09:46So that's gonna make sure that I'm gonna get access to
09:48that core folder, that user local.
09:51Now I'm gonna put your slash
09:52and I'm gonna list out inside of a curly bracket,
09:56all the folders that I really want to change.
09:58So we saw, we had the lib slash node modules,
10:03there's the bin folder,
10:05and again, the bin folder is shared among a lot
10:07of different applications.
10:09And if your device is being used by many other people,
10:12you probably wouldn't wanna change it
10:13and you'd wanna look into our documentation.
10:16But in general, most Macs, at least my Mac,
10:19I'm only working myself.
10:20So it's okay that I'm gonna turn this to be completely mine.
10:23And I'm gonna go ahead and also change the share folder
10:26and close our curly bracket.
10:28So again, I just wanna walk through what I'm doing here.
10:31I'm asking pseudo, I'm asking from the root
10:33to change the owner recursively to be me
10:37of the folders that first,
10:40the folder we got from NPM Config get prefix, which is,
10:42in my case, the user slash local.
10:45And then I want to change the list of folders
10:48that in are in this curly bracket,
10:50which are our lib node modules, our bin folder,
10:53our share folder, and I'm separating them using a comma.
10:57If I go ahead and click on enter, it's gonna go
10:59through the process of changing the owner.
11:01I just have to make sure that I provide the password,
11:04my root password, which I've just done once I
11:08provided the root password.
11:09If I go ahead and I look at who, what are those files,
11:12who owns them, you're gonna see
11:14that our bin folder is now mine completely.
11:17Our share folder is mine completely.
11:20And if I go into my Lib folder, which the lib
11:23by the way is owned by some number,
11:28but I'm gonna, if I go into the Lib folder
11:29and I search for that specific folder,
11:32in our case we're looking for the node modules.
11:35And you'll see in my node modules that not the root owns it,
11:38but actually Ben Fala owns it, which is me,
11:40that this is my username awesomeness.
11:43So now that I've went through all of this process,
11:46I'm gonna clear here, and once I've done
11:48with all this process, I could go ahead
11:50and now my permissions should be set.
11:52So I'm gonna ask from NPM again
11:54to install NPM in our global folder.
11:57I'm not gonna need to use SDU or anything like that.
12:00And by the way, if you can't change those permissions,
12:03you could try and use SDU
12:04or look at other solutions that we have in the documentation
12:07that's provided with this chapter.
12:09But go ahead and even
12:10before we do that, let's see what version, so let's remember
12:13what version of NPM we have here.
12:15NPM minus V, our current version is 3.9393.
12:20And if I'm gonna go again, NPM install NPM minus G,
12:25and I'm gonna go ahead and set up the connection.
12:28It's gonna go through it searching
12:29to see if there's a newer version than 3.9 0.3.
12:34And once it goes through, connects to the web,
12:37finds the file, downloads it,
12:38and installs it, it's gonna go all this process on its own
12:41once you had the configuration set up
12:43and configured correctly.
12:45And you can see that now we updated our version of NPM
12:48to 3.95
12:50and we've upped updated Oso our whatever this is.
12:55Alright, that's it.
12:56And that wraps up our discussion about how do you update NPM
13:01and Oso, how you set up and configure NPM.
13:03So you could start doing all the installs
13:05that we're gonna do throughout this chapter and beyond.
13:08And now we've updated from 3.93 to 3.95.
13:12And I encourage you once in a while
13:14to run this command every few weeks.
13:16Just to make sure that you have the latest version
13:19of NPM in this lecture.
13:22We got to know the basic idea behind NPM
13:25and got NPM to be running
13:29and without permission issues.
13:31In the next lecture, we're gonna go ahead and install
13:34and uninstall global packages.
13:36So by the end of the next lecture, you will know
13:38what global packages are, you'll know what packages are,
13:41and you'll know what global packages are,
13:43and we'll know how to install and uninstall them.