Node.js安装配置教程讲解

  • Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,使用了一个事件驱动、非阻塞式 I/O 的模型,使其轻量又高效。
    Node.js v12.9.1 文档

1.下载、安装nodejs

下载nodejs

Node.js中文网下载地址
下载最新版本,当前版本12.9.1

安装nodejs

在这里插入图片描述

  • 运行安装包,选择相关的路径,默认C:\Program Files (x86)\nodejs
    在这里插入图片描述
  • 默认安装以下四项,add to path会自动配置对应的环境变量,其余的都是直接下一步下一步然后install
    在这里插入图片描述
  • 安装完成,运行node -v npm -v分别查看版本信息,检测是否安装成功。
    在这里插入图片描述

2.安装相关模块环境

  • 键入命令:cd C:\Program Files(x86)\nodejs 即可进入nodejs 安装目录 *C:\Program Files (x86)\nodejs*
    node模块的安装分为全局模式和本地模式。一般情况下会以本地模式运行,包会被安装到和你的应用代码统计的本地node_modules目录下。在全局模式下,Node包会被安装到Node的默认安装目录下的node_modules下。
    在这里插入图片描述
  • 接下来设置环境变量,“我的电脑”-右键-“属性”-“高级系统设置”-“高级”-“环境变量”,系统变量下新建NODE_PATH,填写好对应的路径
    在这里插入图片描述
  • 打开cmd窗口,输入如下命令进行模块的全局安装:
npm install express -g     # -g 全局安装

在这里插入图片描述
在这里插入图片描述
如果沒有-g的话会安装到当前node_modules目录下(如无则新建node_modules文件夹)。

3.throw err;Error: Cannot find module ‘express’ 错误解答

  • This problems seems to be quite popular among Windows users. It seems to occur after node has been reinstalled or updated or when hidden attribute has been removed from C:\Users\IMaster\AppData folder. It might be one of those things that can make you feel bad especially if you don’t wont to apply some quick hacks like: npm link express

  • Node returns error because is not able to find required module and that is why problem in most cases is actually easy to fix. First place to check would be require.paths. After typing it in node console I received:
    Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.

  • At the time of writing I am using v0.6.19 but you might see this or similar warning if you using newer version.

  • As stated you have 2 choices. You can install express (or another module) to local node_modules directory using npm install express or after installing module globally

  • npm install express -g

  • you can link it with your current project using

  • npm link express

  • Second and last option is to create or update NODE_PATH system variable pointing your node to the right place in the system. If you are Windows user use export command as shown below:

  • export NODE_PATH=“C:\Users\IMarek\AppData\Roaming\npm\node_modules”

  • Now you should update PATH variable as well

  • set PATH=%PATH%;%NODE_PATH%

  • Try to run your module now.

  • You should be fine.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值