nodejs详细安装步骤和npm配置

75,075次阅读
没有评论

共计 1432 个字符,预计需要花费 4 分钟才能阅读完成。

1、Node.js 简介

1、Node.js 简介

Node.js® 是一个基于 Chrome V8 引擎的 JavaScript 运行时。Node.js 使用高效、轻量级的事件驱动、非阻塞 I/O 模型。它的包生态系统,npm,是目前世界上最大的开源库生态系统。

2、下载 Node.js

官方地址:https://nodejs.org/en/ 或 https://nodejs.org/zh-cn/

如下图:

nodejs 详细安装步骤和 npm 配置

2、下载 Node.js

官方地址:https://nodejs.org/en/ 或 https://nodejs.org/zh-cn/

如下图:

nodejs 详细安装步骤和 npm 配置

开始安装

1、下载完成后,双击“自己的下载好.msi”文件,开始安装:

nodejs 详细安装步骤和 npm 配置

nodejs 详细安装步骤和 npm 配置

3、选择安装目录, 我选择 D:nodejs,点击“Next”按钮

nodejs 详细安装步骤和 npm 配置

4、选择安装项,此处我选择默认,点击“Next”按钮

nodejs 详细安装步骤和 npm 配置

nodejs 详细安装步骤和 npm 配置

点击“Install”按钮,开始安装

nodejs 详细安装步骤和 npm 配置

等待安装完成,点击“Finish”按钮完成安装

nodejs 详细安装步骤和 npm 配置

五、安装完成查看

1、查看是否安装成功

A、node -v 查看 node 版本

B、npm -v 查看 npm 版本

nodejs 详细安装步骤和 npm 配置

安装完成后,文件目录如下图

nodejs 详细安装步骤和 npm 配置

六、环境配置

此处的环境配置主要配置的是 npm 安装的全局模块所在的路径,以及缓存 cache 的路径,之所以要配置,是因为以后在执行类似:

npm install express [-g](后面的可选参数 -g,g 代表 global 全局安装的意思)的安装语句时,会将安装的模块安装到

【C:Users 用户名 AppDataRoamingnpm】路径中,占 C 盘空间。

这里将全局模块(文件夹名:node_global)和缓存(文件夹名:node_cache)放在了 nodejs 安装目录下

在你的 nodejs 安装目录下创建创建两个文件夹,名称分别为:node_global 和 node_cache

在 node_global 文件夹下再建一个 node_modules 文件夹 (配置环境变量)

nodejs 详细安装步骤和 npm 配置

nodejs 详细安装步骤和 npm 配置

win+ R 打开运行窗口,输入 cmd,再输入以下两条指令

npm config set prefix “D:nodejsnode_global”

npm config set cache “D:nodejsnode_cache”

nodejs 详细安装步骤和 npm 配置

高级系统设置 —– 环境变量

右键我的电脑, 我的属性, 点击高级系统设置

nodejs 详细安装步骤和 npm 配置

nodejs 详细安装步骤和 npm 配置

在系统变量中,新建,变量名:NODE_PATH 变量值:

node_global 文件夹下的 node_modules 文件夹。如:D:nodejsnode_globalnode_modules

nodejs 详细安装步骤和 npm 配置

修改用户变量中的 Path 变量,将默认的 npm 路径修改为新建的 node_global 路径

D:nodejsnode_global

D:nodejsnode_globalnode_modulesyarnbin

D:nodejsnode_globalnode_modulestyarnlib

D:nodejsnode_globalbin

nodejs 详细安装步骤和 npm 配置

1、通过 npm 全局安装 cnpm

npm install -g cnpm

2、将 npm/cnpm 设置为淘宝镜像

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

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

3、查看 npm/cnpm/yarn 镜像地址:

npm config get registry

cnpm config get registry

yarn config get registry

原文地址: nodejs 详细安装步骤和 npm 配置

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-09-30发表,共计1432字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)