使用 npm 命令安装模块

npm 安装 Node.js 模块语法格式如下:

$ npm install <Module Name>

以下实例,我们使用 npm 命令安装常用的 Node.js web框架模块 express:

$ npm install express

安装好之后,express 包就放在了工程目录下的 node_modules 目录中,因此在代码中只需要通过 require(‘express’) 的方式就好,无需指定第三方包路径。

var express = require('express');

镜像源更换

npm 官方原始镜像网址是:https://registry.npmjs.org/ 淘宝 NPM 镜像:http://registry.npmmirror.com 阿里云 NPM 镜像:https://npm.aliyun.com 腾讯云 NPM 镜像:https://mirrors.cloud.tencent.com/npm/ 华为云 NPM 镜像:https://mirrors.huaweicloud.com/repository/npm/ 网易 NPM 镜像:https://mirrors.163.com/npm/ 中国科学技术大学开源镜像站:http://mirrors.ustc.edu.cn/ 清华大学开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/ 腾讯,华为,阿里的镜像站基本上比较全 更换镜像源:

 npm config set registry https://registry.npmmirror.com

返回npm 官方原始镜像

npm config set registry https://registry.npmjs.org/

查看当前的镜像源

npm config get registry