Vue~What you need to know about node and npm

 

 

Table of contents

foreword

1. What are node and npm?

2. The relationship between node and npm

Three, use

1. Download address

2. Install

3. Common commands

    3.1 View node version

    3.2 View npm version

    3.3 View npm installation location

    3.4 View the default storage location of npm cache

    3.5 Modify the default folder of npm download files

4. Set Taobao Mirror

  4.1 Change the default registry of npm to Taobao registry

   4.2 Global installation of cnpm based on Taobao source

Summarize



foreword

 As a front-end development engineer using the Vue framework, if you don't understand or even know what node is? Then you must be out.

 You must know what mpm is, it is a command download tool. Not just download tools! ! !


1. What are node and npm?

Excerpt from the official website: As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications.

To put it bluntly: Node is JavaScript running on the server side.

Node.js is similar in design to   systems like Ruby's Event Machine  or Python's  Twisted . But Node.js takes the event model a step further, presenting the event loop as a runtime construct rather than as a library. In other systems, there is always a blocking call to start the event loop. Typically, the behavior to be performed is defined via a callback at the start of the script, and  EventMachine::run() the server is then started via such a blocking call. In Node.js, however, there is no such call to start the event loop. Node.js enters the event loop directly after executing the input script, and exits the event loop when there are no more callbacks to execute. This behavior is just like browser JavaScript - the event loop is hidden from the user.

HTTP is a first-class citizen in Node.js, designed with streaming and low latency in mind, which makes Node.js ideal as the basis for a networking library or framework.

Node.js is designed to run single-threaded, but that doesn't mean you can't take advantage of multiple cores of your CPU. You can   spawn child processes via the child_process.fork() API, and it's designed to be very easy to communicate with. The cluster module built on top of the same interface   allows you to share sockets (sockets) between processes to achieve core load balancing.

 npm: The full name is Node Package Manager, which is a NodeJS package management and distribution tool, and has become an unofficial standard for releasing Node modules (packages).

2. The relationship between node and npm

When downloading and installing node, npm is also installed. In fact, npm is a set of package management tools built into node.js. Then you can use the npm install ...... command to download the toolkit (dependency) we need.

Three, use

1. Download address

Download | Node.js

2. Install

Node.js installation and configuration | Novice Tutorial

3. Common commands

    3.1 View node version

node -v

    3.2 View npm version

npm -v

    3.3 View npm installation location

npm get prefix

    3.4 View the default storage location of npm cache

npm get cache

    3.5 Modify the default folder of npm download files

 If you do not modify it, it will be installed under the default C drive, which will cause multiple system freezes in the cache download files of the C drive.

1、在 nodejs 安装目录下,创建 “node_global” 和 “node_cache” 两个文件夹

2、设置全局模块的安装路径到 “node_global” 文件夹
   npm config set prefix "nodejs 安装目录\node_global"

3、设置缓存到 “node_cache” 文件夹
   npm config set cache "nodejs 安装目录\node_cache"

4、要把修改后的node_global的路径配置到计算机的 系统变量 下的 PATH 里面,方便直接使用命令行运行
   nodejs 安装目录\node_global

5、测试是否修改完成
   npm install express -g


4. Set Taobao Mirror

Due to the influence of the Internet environment in China, the download of some dependent packages will be very slow, or even fail to download, so the mirror download must be used.

  4.1 Change the default registry of npm to Taobao registry

1、查看当前使用的镜像路径
   npm config get registry

2、修改为淘宝镜像
   npm config set registry https://registry.npm.taobao.org/

3、检查是否修改成功
   npm config get registry

   4.2 Global installation of cnpm based on Taobao source

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

Check whether the cnpm installation is successful

cnpm -v

 


Summarize

 In fact, it is very simple and easy to understand.

おすすめ

転載: blog.csdn.net/weixin_41620505/article/details/126034050