裝了個4.2.2到D:\Dev\nodejs
,準備裝個grunt:html
C:\Users\hey>npm install -g grunt-cli npm WARN deprecated lodash@2.4.2: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^3.0.0. C:\Users\hey\AppData\Roaming\npm\grunt -> C:\Users\hey\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt grunt-cli@0.1.13 C:\Users\hey\AppData\Roaming\npm\node_modules\grunt-cli ├── resolve@0.3.1 ├── nopt@1.0.10 (abbrev@1.0.7) └── findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)
撞到了C盤,並且位置很隱蔽。。node
D:\Dev\nodejs
下默認有一個node_modules
目錄,設置爲裝到該目錄:express
C:\Users\hey>npm get prefix C:\Users\hey\AppData\Roaming\npm C:\Users\hey>npm set prefix D:\Dev\nodejs C:\Users\hey>npm get prefix D:\Dev\nodejs
裝一個express測試下:npm
C:\Users\hey\Desktop\hexo-blog>npm install express -g express@4.13.3 D:\Dev\nodejs\node_modules\express ├── escape-html@1.0.2 ├── merge-descriptors@1.0.0 ├── cookie@0.1.3 ├── array-flatten@1.1.1 ├── cookie-signature@1.0.6 ├── utils-merge@1.0.0 ├── methods@1.1.1 ├── content-type@1.0.1 ├── range-parser@1.0.3 ├── vary@1.0.1 ├── fresh@0.3.0 ├── path-to-regexp@0.1.7 ├── content-disposition@0.5.0 ├── etag@1.7.0 ├── serve-static@1.10.0 ├── parseurl@1.3.0 ├── depd@1.0.1 ├── qs@4.0.0 ├── on-finished@2.3.0 (ee-first@1.1.1) ├── finalhandler@0.4.0 (unpipe@1.0.0) ├── debug@2.2.0 (ms@0.7.1) ├── proxy-addr@1.0.8 (forwarded@0.1.0, ipaddr.js@1.0.1) ├── send@0.13.0 (destroy@1.0.3, statuses@1.2.1, ms@0.7.1, mime@1.3.4, http-errors@1.3.1) ├── accepts@1.2.13 (negotiator@0.5.3, mime-types@2.1.7) └── type-is@1.6.9 (media-typer@0.3.0, mime-types@2.1.7)
可是require卻報錯了:cookie
C:\Users\hey>node > express = require('express') Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:337:15) at Function.Module._load (module.js:287:25) at Module.require (module.js:366:17) at require (module.js:385:17) at repl:1:11 at REPLServer.defaultEval (repl.js:248:27) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer.<anonymous> (repl.js:412:12) at emitOne (events.js:82:20)
解決辦法: 建立環境變量NODE_PATH
,值爲D:\Dev\nodejs\node_modules;
。hexo
測試:dom
C:\Users\letian>node > var express=require('express'); var express=require('express'); undefined >