windows 下安装npm以及cnpm的过程
6 G0 a1 ^; v: d! ^7 [: c( {" f' b( r0 g! m" b! e/ T
安装步骤】 一、安装node.js 1.前往node.js官网下载并安装工具,这里安装路径选到c盘,c:\Program Files\nodejs 安装完毕在命令行输入以下命令测试是否安装成功,正确会出现版本号 . P5 d( V' N. E$ ^
C:\Users\admin>npm -v 6.14.5
' r. u2 i& J# f+ U5 k$ i
+ g9 n, {* c/ C* O2.改变原有的环境变量, (1)我们要先配置npm的全局模块的存放路径以及cache的路径,例如我希望将以上两个文件夹放在NodeJS的主目录下,便在NodeJs下建立"global"及"cache"两个文件夹,输入以下命令改变npm配置 4 G) F+ d$ k) D- f2 x" \
C:\Users\admin>npm config set prefix "c:\Program Files\nodejs\global" # K j# F% V' v1 R% Q; r1 l/ Z
C:\Users\admin>npm config set cache "c:\Program Files\nodejs\cache"
2 D% e, S3 L6 ]! |2 d. @5 B& Y* m5 f2 Q! d; x
(2)在系统环境变量添加系统变量NODE_PATH,输入路径D:\Program Files\nodejs\global\node_modules,此后所安装的模块都会安装到改路径下
2 w* _: \$ P3 e- D1 z* t- a$ Y2 K9 u$ {6 E6 J
3)在命令行输入以下命令试着安装express(注:“-g”这个参数意思是装到global目录下,也就是上面说设置的“D:\Program Files\nodejs\global”里面。)
2 |1 `1 B4 I0 L0 K1 g4 p7 _4 M
5 U7 [+ N! B/ P5 H
) Q) f$ r3 b2 G# C- o0 t+ jC:\Users\admin>npm install express -g' t$ {/ J' {8 Q, N# _0 p$ Z: l* E
npm WARN notsup Unsupported engine for express@5.1.0: wanted: {"node":">= 18"} (current: {"node":"12.18.2","npm":"6.14.5"})
: P* C/ a' Q+ J$ d7 K: N6 _4 lnpm WARN notsup Not compatible with your version of node/npm: express@5.1.0$ g1 O: T P0 H# v+ B
npm WARN notsup Unsupported engine for router@2.2.0: wanted: {"node":">= 18"} (current: {"node":"12.18.2","npm":"6.14.5"})5 A8 D' `# x" Y% Z
npm WARN notsup Not compatible with your version of node/npm: router@2.2.09 H( a' V, j f. m4 N
npm WARN notsup Unsupported engine for send@1.2.0: wanted: {"node":">= 18"} (current: {"node":"12.18.2","npm":"6.14.5"})npm WARN notsup Not compatible with your version of node/npm: send@1.2.05 z3 V% G: L5 s$ Z( N: Z6 @
npm WARN notsup Unsupported engine for body-parser@2.2.0: wanted: {"node":">=18"} (current: {"node":"12.18.2","npm":"6.14.5"})
7 ~1 t3 G" `4 C9 L& x" @1 cnpm WARN notsup Not compatible with your version of node/npm: body-parser@2.2.0
* ^7 W5 b6 R+ l# O( }npm WARN notsup Unsupported engine for serve-static@2.2.0: wanted: {"node":">= 18"} (current: {"node":"12.18.2","npm":"6.14.5"})
' u) K: G H3 U. c( S* Hnpm WARN notsup Not compatible with your version of node/npm: serve-static@2.2.04 _% O" w+ @2 Z1 U6 h
npm WARN notsup Unsupported engine for merge-descriptors@2.0.0: wanted: {"node":">=18"} (current: {"node":"12.18.2","npm":"6.14.5"})
8 E/ E- `! g- m. ~0 h: hnpm WARN notsup Not compatible with your version of node/npm: merge-descriptors@2.0.0- w7 G; }6 O$ l' g2 P, I; C
npm WARN notsup Unsupported engine for path-to-regexp@8.2.0: wanted: {"node":">=16"} (current: {"node":"12.18.2","npm":"6.14.5"})! V) c. x% T# X3 A% E
npm WARN notsup Not compatible with your version of node/npm: path-to-regexp@8.2.0
1 i% U; {* c$ P; S" |( H( a( x* n8 h% }
+ express@5.1.01 Y0 W/ Z O* \% \; ~
added 66 packages from 42 contributors in 18.426s" O) c, V. U; c' Q& D6 R* L
3 w) F+ m3 w3 m f3 |
安装完成之后,既可以查到到nodejs目录下global目录有内容了。
+ s, M% x) V. F- N5 p& Q
, {; G5 Q0 V$ L) |* l1 b4 h> require('express')
: H5 K Z1 Y7 ^8 f9 r5 C9 XUncaught Error: Cannot find module 'express'' t6 g8 G! [# u3 j0 v
Require stack:
7 y% r1 @; v* T6 t: N' T- <repl>4 g: M' n: c8 f" I5 G- Q1 f8 ~ s
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)/ Q1 P4 F& P2 [/ x, o
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
0 n' }) B8 Y3 ` at Module.require (internal/modules/cjs/loader.js:1026:19) h+ v5 O2 {$ R8 q B. I
at require (internal/modules/cjs/helpers.js:72:18) {+ |6 C- ?3 S) \9 Q
code: 'MODULE_NOT_FOUND',) O; f% Y+ F. F: {+ ?; C) _
requireStack: [ '<repl>' ]: `1 `4 b% v- w. h6 p
}' \3 t* L" f' ~+ O
) W' j. p4 j) C/ q! m# x假设成功,可以看到有输出。假设出错,检查NODE_PATH的路径。) {3 I/ t- z. \, D
, t* N. i6 N8 g
8 N9 P, p: V! F) v5 E |