As a front-end, everyone should be very familiar with NPM install, especially the crazy output of the command window during the execution of the command. I found that some students are familiar with the installation of the package, but they don’t know where the package comes from and how to release an NPM very well. Based on this, I made a sharing within the team, and organized the sharing process as follows, hoping to help each student who wants to release their own package but doesn’t know where to start.
Because the release package involves the stages of release, installation, update, deletion / abandonment, etc., it is too long to write in an article, so it is decided to break it into a series. Today’s first article introduces some knowledge about NPM.
1、 NPM (node
- Is a front-end development aidPackage management tools
- Website: find package, register user
- Command line: the main form of interaction between programmers and NPM
- Management object: package
- Add (publish: NPM publish; install: NPM I)
- Delete (discard: NPM delete; uninstall: NPM RM)
- Change (update: NPM up)
- Search (search: NPM s)
There are two main bodies involved in NPM:packageandmodule, as defined below:
Include package.json description fileand
Publish to NPM warehouseFiles or folders for
In node modulesYes, you can.
Loaded by the require() method of node.jsAny file or folder for
It can be understood as follows:
In addition, based on the above, we can see the relationship between package and module:
- Module does not have to be a package (such as node built-in module). Package must be a module
- The module with package.json file must be package
In addition to the above concepts, let’s look at the details of the following two main bodies:
There are two important attributes:
Once you register an individual or group account, you will get a scope that matches the individual or group name. You can use this scope as the package namespace, such as @ yuyy, @ 58.
- Unscoped: for example, Babel
- User: for example @ yuyy / Babel
Role: provide a namespace for your own published packages to prevent conflicts with other package names
The property values are:
- Private: private, visible only to the author or team member
- Public: public, visible to all
This attribute is consistent with the accessibility policy set when GitHub creates a warehouse: public, visible to all, free; private, visible only to itself, charged.
The relationship between the above two attributes is as follows:
Several points need to be explained:
- Individual account (user) can create and manage unscoped package; team account (ORG) can only manage scoped package
- Unscoped is always public
- Private package is always scoped
The package of scoped is private by default, but it needs to be paid, whose properties can be changed from the command line
The module downloaded to the local is mainly used to be referenced in the node environment. In order to be loaded by the require() method of node.js, the module must be one of the following situations:
- Folder containing package.json with main field in package.json
- Folder with index.js
All of the above are NPM related knowledge. In the next NPM publishing package tutorial (2): Publishing package, we start to demonstrate the actual operation process of publishing NPM package.
1. NPM release package tutorial (1): from NPM
2. NPM release package tutorial (2): release package
3. NPM release package tutorial (3): install release package
4. NPM release package tutorial (4): iteration
5. NPM release package tutorial (5): discard / delete