Fill in account information, Full Name, Public Email, Username, Password
Click Create an Account to register
Log in to your email, click the verification link to verify your account
After registration, log in to the terminal
The npm address before each login has to be switched to the official server address, and the mirror address cannot be used.
npm install -g nrm
nrm use npm
Execute the npm login command, enter the user name, password, and email address in sequence, and the login is successful.
In the following situations, you have to go to the mailbox to get the verification code and enter it
If this starts, the login is successful
Publish the package on npm
Switch the terminal to the root directory and run the npm publish command to publish the package to npm (note: the package name cannot be the same)
cd root directory name
npm publish
remove published package
npm unpublish package name --force, you can delete, only delete within 72 hours,
With packages deleted in this way, republishing is not allowed within 24 hours
Module loading mechanism
Load from cache first
Modules are cached after the first load, which also means that require() will not cause the module's code to be executed multiple times
Whether it is a built-in module, a user-defined module, or a third-party module, they will be loaded from the cache first, thereby improving the loading efficiency of the module
Loading mechanism for built-in modules
Built-in modules have the highest loading priority
For example, when importing the built-in fs module, the custom module also has fs, but the priority of importing is the fs of the built-in module
Loading mechanism for custom modules
When loading a custom module, you must specify a path identifier starting with ./ or .../, if not specified, node will treat the custom module as a built-in module or a third-party module
When importing a custom module, if the extension of the file is omitted, node.js will try to load the following files in order
1. Load according to the exact file name
2. Complete the .js extension loading
3. Complete the .json extension loading
4. Complete the .node extension for loading
Failed to load, error
Loading mechanism for third-party modules
When it is neither a built-in module nor a custom module, node.js will start from the parent directory of the current module and try to find the /node_modules folder to load the third-party module. directory, look for node_modules
Loading mechanism when a directory is a module
1. Find a file called package.json in the loaded directory, and look for the main attribute as the entry for require() loading
2. When there is no package.json file or the main entry does not exist, node.js will load the index.js file in the directory
3. If all fail, an error message will be printed and the missing module will be reported