Node.js安装配置教程讲解

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

1.下载、安装nodejs

下载nodejs

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

安装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文件夹)。web

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 expressexpress

  • 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.npm

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

  • 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 globallyapp

  • npm install express -gsvg

  • you can link it with your current project usingui

  • npm link expressthis

  • 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:3d

  • 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.