You can use the NPM command-line tool to manage your private module code in the NPM repository, which makes it easier to use public modules in your project.
Work before the start
You need a 2.7.0 version of NPM and need an account that can be logged into the NPM repository.
Install -Login
Package settings
All private modules are scoped package.
Scope is a new feature of NPM. If the name of a module starts with "@", then he is a scoped package. Scope is the part between "@" and "/".
@scope/project-name
When you register a private module under a user, your scope is the user name of the current user.
@username/project-name
If you want to initialize a package with NPM init, you can set your scope by customizing the--scope option
NPM Init--scope=<your_scope>
If you are using the same scope most of the time, you can set a default scope so that the scope will be used automatically when we initialize.
NPM Config set scope <your_scope>
Release module
The operation of releasing a module is very simple.
NPM Publish
By default, the scoped package is published as a private module, which is billed as a private module and costs $7 per month. For more detailed information, refer to the NPM (Node Package Manager) Primer-Basic usage
Once the release is complete, you will see your scoped package on the NPM library site, with a private logo stating that the module is non-public and cannot be used by others.
Authorizing other members to access
If you want to authorize other people to use your module, you can set which users can have read-only or read-write permissions on the package's Permissions Settings page. You can also use the command line to make the relevant settings
NPM owner Add <user> <package name>
Installing private modules
If you want to install a private module, you must have permission to access the private module that you want to install. When installing, you can use the scope package name
Install @scope/project-name
When you use these code modules in your project, you can use the following
var project = require (' @scope/project-name ')
Set the private module to a common
All scoped packages are private by default, which ensures that unrelated people cannot access the module. You can also modify the module to public state.
You can also use the command line to manipulate
NPM Access restricted <package_name>
This operation may take several minutes to take effect, and the Web site will remove the module from the private list.
Write it in the back.
If you have any questions about this translation, please leave a message below, or you can Web front-end senior engineer Group for online communication.
This article is translated from NPM official document Https://docs.npmjs.com/private-modules/intro
Management use of NPM private modules