- [Instructor] Now we've explored how to publish a package,
but what if you'd like to publish a scope package instead
like Angular does with their own packages.
Let me show you how it works.
So the first thing we're going to do is create a brand
new folder just for that scope package.
So we'll do a right click, new folder,
and then I'm going to call this NPMScoped.
And then let's open a brand new folder in this area.
Go to desktop.
And I'm going to copy some of the stuff from this guy here.
So I'm going to copy the read me file, the index,
and the babblerc, and then paste it in the NPMScoped.
Now what we're going to do is drag and drop this folder
inside of Vscode, or you can right click and then
open in Vscode on Windows.
If you don't have the terminal open,
you click on view, terminal
and it's going to open the terminal.
Now how do you init the package dot json file
for scope packages is slightly different.
So let's go ahead and do this.
So npm init,
and what you do is dash, dash, scope
equals, and then the name of the organization,
or the name of the author, or whatever you want to be
at the at sign before the name of the package.
So, in this case I'm going to put algofields,
and this is what is going to appear inside of my package.
So if I do this, it's going to init
my package dot json file with the name at algofields
forward slash npmscoped, and then version one
and blah, blah, blah.
If you have a project, or if you are watching this
course to learn how to publish to npm with a full
project that you want to publish, feel free to enter
all the other fields here such as description,
git repository, and so on so forth.
(typing clicks)
Perfect, so we're going to have a brand new packaged dot
json file, and as you can see now it is scoped.
So at algofields forward slash npmscoped.
So if someone wants to install this they need to
do the full name as so.
So when we're ready to publish,
all we have to do is do npm publish.
And by the way, if you want to publish scope packages
you need to have a paid account.
The reason being is by default scope packages are
published as private.
In order to publish private packages,
you need to have a paid account.
In this case I do, so I'm going to do npm publish.
And I'm just going to add a tag, call this
scoped, and I have my brand new, private packages
published to npm like so.
So as I just explained, by default scope packages
will be automatically private, and this is what we want.
But if you wanted to create a scope package
and make it available publicly, you'd do this by
doing npm publish
dash, dash access public.
This way this package would be public
as opposed to be private.
I'm not going to do that, but this is how you'd do it.