NPM publishing package tutorial (1): from NPM


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 (nodepackage manager)

  • Is a front-end development aidPackage management tools
  • Include:

    • Website: find package, register user
    • Command line: the main form of interaction between programmers and NPM
    • Warehouse: the largest JavaScript software library
  • Management object: package
  • Management mode:

    • 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:

  • package:Include package.json description fileandPublish to NPM warehouseFiles or folders for
  • module:In node modulesYes, you can.Loaded by the require() method of node.jsAny file or folder for

It can be understood as follows:A JavaScript software is package when it is released to NPM warehouse locally, and becomes module when it is downloaded to NPM warehouse locally

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:

2、 Package

There are two important attributes:

1.Scope(scope, scope)

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
  • scoped

    • User: for example @ yuyy / Babel
    • org:@babel/parser

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:

NPM publishing package tutorial (1): from NPM

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

3、 Module

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
  • JavaScript files

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.

Related articles:
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