- Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,使用了一个事件驱动、非阻塞式 I/O 的模型,使其轻量又高效。
Node.js v12.9.1 文档
1.下载、安装nodejs
下载nodejs
安装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.