Writing in the front

With VUE3.0 and Webpack5 released over the weekend, tech anxiety is back? The anxiety and self-curiosity driven by the overwhelming source code analysis made me put down what I was learning and quickly looked at the latest technology. As a result, the new did not learn, and the old gave up halfway.

In Huainan Zi Shuo Lin Xun, Han Liu ‘an said:

The deer hunter ignores the hareCopy the code

Do not focus on only one thing, as a result, often all things fall by the wayside. So, even though VUE and Webpack have been updated, node.js will continue to be chosen for this section.

The last review

If you are reading this article for the first time, it is highly recommended that you start with the first section. You will get a lot more out of this series. There is no exaggerated title, but the content is broad enough to give you a different interpretation. At the same time, each article is not many words, 5-10 minutes to read, if the time is not enough, you can click to follow or like, in the future, you can find this series of articles in the “dynamic”.

Click here to skip to the chapters to read: Node.js Introduction Series (1) Features, application scenarios, front-end pain points solved problems Node.js introduction series (2) modules, REPL Node.js introduction series (3) development and debugging, global built-in functions and variables Webpack Principle and Practice (I) Why choose Webpack




Learning objectives in this section

1) Basic knowledge and use of NPM 2) simple process of NPM package release

Learn the table of contents in this section

Basic knowledge and use of NPM

How to publish your OWN NPM package

Three summaries of this section

Notice of the next period

At the end of the five article

Basic knowledge and use of NPM

What is NPM?

NPM is the package management tool for Node.js. You can think of it as a module manager for Node.js.

Where does NPM come from?

NPM is installed along with Node.js, which means that NPM is already installed. Therefore, using NPM requires no additional installation.

How do I know if node.js is also installed successfully with NPM?

You can test for a successful installation by typing “NPM -v”. If the version number is printed on the command line, the installation is successful.

NPM version is old, I want to update to the latest version, what should I do?
npm install npm -g
Copy the code
What exactly does NPM do?

NPM has three main functions:

1) Allow users to download third-party packages written by others from the NPM server for local use. 2) Allow users to download and install command line programs written by others from NPM server for local use. 3) Allow users to upload their own packages or command-line programs to the NPM server for others to use.

In summary, NPM is a means of communication between the local package and the server, whether you want to use another package, or want others to use your package, you can connect through NPM.

How to install third-party packages?

NPM three functions first – download the third-party package written by others to local use, use the command is very simple, first you have to know others that package on the server called what name, and then you can targeted to download it, syntax is as follows:

npm install <Module Name>
Copy the code
I only installed a package, why so slow, can you quickly install?

NPM is quite slow to pull resources from the remote server. In order to solve this problem, many domestic enterprises have developed mirrors. There are many types of mirrors, including Taobao mirror resource library, which is commonly used in several large mirror libraries.

npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code

From then on, third-party packages can be installed using CNPM, greatly speeding up connection speeds.

I am installing a package and there is an error midway. How do I delete and reinstall it?

If there is installation, there is deletion. The command for deletion is:

cnpm uninstall <Module Name>
Copy the code

In addition, there are the following common commands: Update module:

cnpm update <Module Name>
Copy the code

Search module:

cnpm search <Module Name>
Copy the code
summary

Data operation four Kings: add, delete, change and check. We found that the NPM operation introduced above involves the increase, deletion, change and check. Can you find that we are operating other people’s packages, can we add a new package in the way of “increase”? How to publish the package written by ourselves?

How to publish your OWN NPM package

Before we can publish our own packages, we need to do some basic preparatory work: 1) Register an NPM account

Website: https://www.npmjs.com/signupCopy the code

Be careful with your name and use it later when you publish it

2) Install NRM globally

CNPM I NRM -g // NRM is a module that manages the NPM warehouse and controls the NPM warehouseCopy the code

3) Check the package file structure to be distributed. NPM recommends that packages contain at least three of the following files:

* package.json (basic description of the package, including versions and names of other packages that depend on it) * readme.md (documentation for users to quickly learn about the package) * index.js (entry file, the first file to parse the package)

If package.json is not available, it can be generated using the following syntax:

cnpm init
Copy the code

If you don’t have readme. md, you need to file it manually and write it using MarkDown syntax.

If you don’t have an index.js file, you need to create the file manually and write the entry file using the JS syntax.

When the content is complete and the above three files are available, the last step is to publish. The syntax is as follows:

cnpm publish
Copy the code

If there are no other errors, then you can go to the website to search for the third party package you just released:

Website: https://www.npmjs.com/Copy the code

At this point, we have completed the entire process of publishing the NPM package. It should be noted that NPM has been merged by GitHub, which makes NPM has a strong backup support, usually their own packaging third-party libraries, can be published to NPM, so that remote use.

In fact, there is also the development of regional packages, and package iteration and maintenance, but the purpose of this article is to understand the basic knowledge and role of NPM, the detailed maintenance process can be practiced again when practical needs.

Well, with the NPM package release process, add, delete, check and change properties are complete.

Three summaries of this section

0) How does Node.js implement module management? 1) How to add, delete, check and modify NPM package? 2) If you want to implement tool function encapsulation sharing, what are your plans? 3) What are the basic processes and requirements for releasing an NPM package?

Notice of the next period

At this point, node.js is already the sixth chapter, and the basic knowledge is basically sound. From the first quick read, recall and summarize the basics of Node.js outlined in six articles.

At the end of the four,

Good article, need your support, click a like, comment section front sofa welcome to exchange.

Front-end pattern, take you to see the depth of the front-end world, build their own knowledge structure

Focus on me. Run faster.