引:在安装完nodejs后,通过npm下载全局模块默认安装到{%USERDATA%}C:\Users\username\AppData\下的Roaming\npm下,这当然是不太对的默认。

1,安装LTS版本的nodejs,本文为v6.10.2 (includes npm 3.10.10) .msi,nodejs安装路径会自动添加到PATH环境变量;

本文安装路径为:D:\Program Files\nodejs

修改完成之后:

2,在nodejs安装路径下新建文件夹node_cache用来存放下载包的缓存; 即:D:\Program Files\nodejs\node_cache;

3,运行 npm config set cache "D:\Program Files\nodejs\node_cache" 设置缓存文件夹;

运行npm config set prefix "D:\Program Files\nodejs"设置全局模块存放路径;

注意:nodejs会自动寻找该路径下的node_modules文件夹为实际存放全局模块的路径,这也是为啥叫prefix不叫global的原因;

以后安装的全局模块都会被放到D:\Program Files\nodejs\node_modules下,跟npm模块在一个文件夹中;

4,修改D:\Program Files\nodejs\node_modules\npm\npmrc文件,将默认值改为:

prefix=D:\Program Files\nodejs,如果不做这个修改,则npm在运行 npm ls  -g 的时候,仍然以默认的路径来查找已安装的全局模块;

5,运行npm install express -g 以全局方式安装express模块,可发现,在D:\Program Files\nodejs\node_modules下出现express文件夹;

6,运行npm list -g ,列出所有全局模块:

D:\Program Files\nodejs
+-- express@4.15.2
| +-- accepts@1.3.3
| | +-- mime-types@2.1.15
| | | `-- mime-db@1.27.0
| | `-- negotiator@0.6.1
| +-- array-flatten@1.1.1
| +-- content-disposition@0.5.2
| +-- content-type@1.0.2
| +-- cookie@0.3.1
| +-- cookie-signature@1.0.6
| +-- debug@2.6.1
| | `-- ms@0.7.2
| +-- depd@1.1.0
| +-- encodeurl@1.0.1
| +-- escape-html@1.0.3
| +-- etag@1.8.0
| +-- finalhandler@1.0.2
| | +-- debug@2.6.4
| | | `-- ms@0.7.3
| | `-- unpipe@1.0.0
| +-- fresh@0.5.0
| +-- merge-descriptors@1.0.1
| +-- methods@1.1.2
| +-- on-finished@2.3.0
| | `-- ee-first@1.1.1
| +-- parseurl@1.3.1
| +-- path-to-regexp@0.1.7
| +-- proxy-addr@1.1.4
| | +-- forwarded@0.1.0
| | `-- ipaddr.js@1.3.0
| +-- qs@6.4.0
| +-- range-parser@1.2.0
| +-- send@0.15.1
| | +-- destroy@1.0.4
| | +-- http-errors@1.6.1
| | | `-- inherits@2.0.3
| | `-- mime@1.3.4
| +-- serve-static@1.12.1
| +-- setprototypeof@1.0.3
| +-- statuses@1.3.1
| +-- type-is@1.6.15
| | `-- media-typer@0.3.0
| +-- utils-merge@1.0.0
| `-- vary@1.1.1
`-- npm@3.10.10
+-- abbrev@1.0.9
+-- ansi-regex@2.0.0
+-- ansicolors@0.3.2
+-- ansistyles@0.1.3
+-- aproba@1.0.4
+-- archy@1.0.0
+-- asap@2.0.5
+-- chownr@1.0.1
+-- cmd-shim@2.0.2
+-- columnify@1.5.4
| `-- wcwidth@1.0.0
| `-- defaults@1.0.3
| `-- clone@1.0.2
+-- config-chain@1.1.11
| `-- proto-list@1.2.4
+-- debuglog@1.0.1
+-- dezalgo@1.0.3
+-- editor@1.0.0
+-- fs-vacuum@1.2.9
+-- fs-write-stream-atomic@1.0.8
+-- fstream@1.0.10
+-- fstream-npm@1.2.0
| `-- fstream-ignore@1.0.5
| `-- minimatch@3.0.3
| `-- brace-expansion@1.1.6
| +-- balanced-match@0.4.2
| `-- concat-map@0.0.1
+-- glob@7.1.0
| +-- fs.realpath@1.0.0
| +-- minimatch@3.0.3
| | `-- brace-expansion@1.1.6
| | +-- balanced-match@0.4.2
| | `-- concat-map@0.0.1
| `-- path-is-absolute@1.0.1
+-- graceful-fs@4.1.9
+-- has-unicode@2.0.1
+-- hosted-git-info@2.1.5
+-- iferr@0.1.5
+-- imurmurhash@0.1.4
+-- inflight@1.0.5
+-- inherits@2.0.3
+-- ini@1.3.4
+-- init-package-json@1.9.4
| +-- glob@6.0.4
| | +-- minimatch@3.0.3
| | | `-- brace-expansion@1.1.6
| | | +-- balanced-match@0.4.2
| | | `-- concat-map@0.0.1
| | `-- path-is-absolute@1.0.0
| `-- promzard@0.3.0
+-- lockfile@1.0.2
+-- lodash._baseindexof@3.1.0
+-- lodash._baseuniq@4.6.0
| +-- lodash._createset@4.0.3
| `-- lodash._root@3.0.1
+-- lodash._bindcallback@3.0.1
+-- lodash._cacheindexof@3.0.2
+-- lodash._createcache@3.1.2
+-- lodash._getnative@3.9.1
+-- lodash.clonedeep@4.5.0
+-- lodash.restparam@3.6.1
+-- lodash.union@4.6.0
+-- lodash.uniq@4.5.0
+-- lodash.without@4.4.0
+-- mkdirp@0.5.1
| `-- minimist@0.0.8
+-- node-gyp@3.4.0
| +-- minimatch@3.0.3
| | `-- brace-expansion@1.1.6
| | +-- balanced-match@0.4.2
| | `-- concat-map@0.0.1
| +-- npmlog@3.1.2
| | +-- are-we-there-yet@1.1.2
| | | `-- delegates@1.0.0
| | +-- console-control-strings@1.1.0
| | +-- gauge@2.6.0
| | | +-- has-color@0.1.7
| | | +-- object-assign@4.1.0
| | | +-- signal-exit@3.0.0
| | | +-- string-width@1.0.2
| | | | +-- code-point-at@1.0.0
| | | | | `-- number-is-nan@1.0.0
| | | | `-- is-fullwidth-code-point@1.0.0
| | | | `-- number-is-nan@1.0.0
| | | `-- wide-align@1.1.0
| | `-- set-blocking@2.0.0
| `-- path-array@1.0.1
| `-- array-index@1.0.0
| +-- debug@2.2.0
| | `-- ms@0.7.1
| `-- es6-symbol@3.1.0
| +-- d@0.1.1
| `-- es5-ext@0.10.12
| `-- es6-iterator@2.0.0
+-- nopt@3.0.6
+-- normalize-git-url@3.0.2
+-- normalize-package-data@2.3.5
| `-- is-builtin-module@1.0.0
| `-- builtin-modules@1.1.1
+-- npm-cache-filename@1.0.2
+-- npm-install-checks@3.0.0
+-- npm-package-arg@4.2.0
+-- npm-registry-client@7.2.1
| +-- concat-stream@1.5.2
| | +-- readable-stream@2.0.6
| | | +-- core-util-is@1.0.2
| | | +-- isarray@1.0.0
| | | +-- process-nextick-args@1.0.7
| | | +-- string_decoder@0.10.31
| | | `-- util-deprecate@1.0.2
| | `-- typedarray@0.0.6
| +-- npmlog@3.1.2
| | +-- are-we-there-yet@1.1.2
| | | `-- delegates@1.0.0
| | +-- console-control-strings@1.1.0
| | +-- gauge@2.6.0
| | | +-- has-color@0.1.7
| | | +-- object-assign@4.1.0
| | | +-- signal-exit@3.0.0
| | | +-- string-width@1.0.2
| | | | +-- code-point-at@1.0.0
| | | | | `-- number-is-nan@1.0.0
| | | | `-- is-fullwidth-code-point@1.0.0
| | | | `-- number-is-nan@1.0.0
| | | `-- wide-align@1.1.0
| | `-- set-blocking@2.0.0
| `-- retry@0.10.0
+-- npm-user-validate@0.1.5
+-- npmlog@4.0.0
| +-- are-we-there-yet@1.1.2
| | `-- delegates@1.0.0
| +-- console-control-strings@1.1.0
| +-- gauge@2.6.0
| | +-- has-color@0.1.7
| | +-- object-assign@4.1.0
| | +-- signal-exit@3.0.0
| | +-- string-width@1.0.2
| | | +-- code-point-at@1.0.0
| | | | `-- number-is-nan@1.0.0
| | | `-- is-fullwidth-code-point@1.0.0
| | | `-- number-is-nan@1.0.0
| | `-- wide-align@1.1.0
| `-- set-blocking@2.0.0
+-- once@1.4.0
+-- opener@1.4.2
+-- osenv@0.1.3
| +-- os-homedir@1.0.1
| `-- os-tmpdir@1.0.1
+-- path-is-inside@1.0.2
+-- read@1.0.7
| `-- mute-stream@0.0.5
+-- read-cmd-shim@1.0.1
+-- read-installed@4.0.3
| `-- util-extend@1.0.3
+-- read-package-json@2.0.4
| +-- glob@6.0.4
| | +-- minimatch@3.0.3
| | | `-- brace-expansion@1.1.6
| | | +-- balanced-match@0.4.2
| | | `-- concat-map@0.0.1
| | `-- path-is-absolute@1.0.0
| `-- json-parse-helpfulerror@1.0.3
| `-- jju@1.3.0
+-- read-package-tree@5.1.5
+-- readable-stream@2.1.5
| +-- buffer-shims@1.0.0
| +-- core-util-is@1.0.2
| +-- isarray@1.0.0
| +-- process-nextick-args@1.0.7
| +-- string_decoder@0.10.31
| `-- util-deprecate@1.0.2
+-- readdir-scoped-modules@1.0.2
+-- realize-package-specifier@3.0.3
+-- request@2.75.0
| +-- aws-sign2@0.6.0
| +-- aws4@1.4.1
| +-- bl@1.1.2
| | `-- readable-stream@2.0.6
| | +-- core-util-is@1.0.2
| | +-- isarray@1.0.0
| | +-- process-nextick-args@1.0.7
| | +-- string_decoder@0.10.31
| | `-- util-deprecate@1.0.2
| +-- caseless@0.11.0
| +-- combined-stream@1.0.5
| | `-- delayed-stream@1.0.0
| +-- extend@3.0.0
| +-- forever-agent@0.6.1
| +-- form-data@2.0.0
| | `-- asynckit@0.4.0
| +-- har-validator@2.0.6
| | +-- chalk@1.1.3
| | | +-- ansi-styles@2.2.1
| | | +-- escape-string-regexp@1.0.5
| | | +-- has-ansi@2.0.0
| | | `-- supports-color@2.0.0
| | +-- commander@2.9.0
| | | `-- graceful-readlink@1.0.1
| | +-- is-my-json-valid@2.15.0
| | | +-- generate-function@2.0.0
| | | +-- generate-object-property@1.2.0
| | | | `-- is-property@1.0.2
| | | +-- jsonpointer@4.0.0
| | | `-- xtend@4.0.1
| | `-- pinkie-promise@2.0.1
| | `-- pinkie@2.0.4
| +-- hawk@3.1.3
| | +-- boom@2.10.1
| | +-- cryptiles@2.0.5
| | +-- hoek@2.16.3
| | `-- sntp@1.0.9
| +-- http-signature@1.1.1
| | +-- assert-plus@0.2.0
| | +-- jsprim@1.3.1
| | | +-- extsprintf@1.0.2
| | | +-- json-schema@0.2.3
| | | `-- verror@1.3.6
| | `-- sshpk@1.10.1
| | +-- asn1@0.2.3
| | +-- assert-plus@1.0.0
| | +-- bcrypt-pbkdf@1.0.0
| | +-- dashdash@1.14.0
| | +-- ecc-jsbn@0.1.1
| | +-- getpass@0.1.6
| | +-- jodid25519@1.0.2
| | +-- jsbn@0.1.0
| | `-- tweetnacl@0.14.3
| +-- is-typedarray@1.0.0
| +-- isstream@0.1.2
| +-- json-stringify-safe@5.0.1
| +-- mime-types@2.1.12
| | `-- mime-db@1.24.0
| +-- node-uuid@1.4.7
| +-- oauth-sign@0.8.2
| +-- qs@6.2.1
| +-- stringstream@0.0.5
| +-- tough-cookie@2.3.1
| `-- tunnel-agent@0.4.3
+-- retry@0.10.0
+-- rimraf@2.5.4
+-- semver@5.3.0
+-- sha@2.0.1
+-- slide@1.1.6
+-- sorted-object@2.0.1
+-- strip-ansi@3.0.1
+-- tar@2.2.1
| `-- block-stream@0.0.8
+-- text-table@0.2.0
+-- uid-number@0.0.6
+-- umask@1.1.0
+-- unique-filename@1.1.0
| `-- unique-slug@2.0.0
+-- unpipe@1.0.0
+-- validate-npm-package-license@3.0.1
| +-- spdx-correct@1.0.2
| | `-- spdx-license-ids@1.2.0
| `-- spdx-expression-parse@1.0.2
| +-- spdx-exceptions@1.0.4
| `-- spdx-license-ids@1.2.0
+-- validate-npm-package-name@2.2.2
| `-- builtins@0.0.7
+-- which@1.2.11
| `-- isexe@1.1.2
+-- wrappy@1.0.2
`-- write-file-atomic@1.2.0

包含了express和npm两个模块,及其依赖模块;

7,最后有洁癖的同学可以将用户环境变量中的默认路径删除;

本文包含的方法,并不需要另外设置PATH变量;

-End-

nodejs prefix(全局)和cache(缓存)windows下设置的更多相关文章

  1. 在Windows下设置环境变量 运行mysql程序变得更容易

    在Windows下设置环境变量,点开始菜单,右键单击我的电脑--属性--高级--环境变量 可以看到PATH的变量是这样的: C:\WINDOWS;C:\WINDOWS\COMMAND   为了让运行m ...

  2. windows下设置JupyterNotebook默认目录

    目录 windows下设置JupyterNotebook默认目录 生成配置文件 设置默认工作目录 设置快捷方式中的目标与起始位置 直接修改anaconda中的相关配置文件 windows下设置Jupy ...

  3. Windows下设置Ubuntu引导项

    最近在进行一些实验环境的配置,最终通过双系统实现了多系统的管理,而不仅限于虚拟机的方式.以此方式成功安装了Windows8.1 Pro和Windows 10,原文在此. 在此基础上进一步安装了 Ubu ...

  4. windows下设置/删除Tomcat的开机自启动

    绿色版tomcat在配置好Java环境以后直接运行bin下面的startup.bat就能够正常启动,但是在客户这里很多时候都 需要tomcat开机自动启动.下面简单介绍一如何在windows下面开机自 ...

  5. windows下设置计划任务自动执行PHP脚本

    背景: 环境部署在linux下或者windows中,可以使用windows的自动任务设置自动执行脚本执行一些日常运维任务 图形界面设置相对比较简单 准备工作: wamp(集成的PHP执行环境) 已经写 ...

  6. Windows下设置Mongodb用户名密码

    MongoDB认证: 在默认的情况下,Mongodb是监听在127.0.0.1 IP上的,端口号默认为27017,任何客户端都可以连接,不需要认证 默认情况下,Mongodb也是没有管理账户的,除非你 ...

  7. [转]windows下设置socket的connect超时

    原文地址:http://www.cnblogs.com/BloodAndBone/archive/2012/05/22/2513338.html 变相的实现connect的超时,我要讲的就是这个方法, ...

  8. Windows下设置 ssh key,配置GitHub ssh key

    1.新建一个目录,利用git工具打开 Git Bash Here 2.执行如下命令 ssh-keygen -t rsa -C "email@email.com" 其中邮箱为GitH ...

  9. windows 下设置nginx负载均衡

    #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice; #error ...

随机推荐

  1. java框架篇---hibernate(一对一)映射关系

    对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发展而产生的,是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术,本质上就是将数据从 ...

  2. InstallShield:卸载时文字叠加,文字乱码

    问题: InstallShield2010打包的程序.如果程序正在运行,卸载程序,提示关闭程序,然后消息界面出现文字叠加. 定位问题: 新建Installshield项目,依次修改SetupType, ...

  3. Linux下跑程序,防止命令终端(断网,断电)

    有时候我们在服务器上跑程序,会发现当我们离开窗口时,正在执行的程序中断了,这让人非常郁闷.下面介绍防止程序中断的方法: 新建一个名为yourname的Screen窗口: screen -S yourn ...

  4. React性能分析利器来了,妈妈再也不用担心我的React应用慢了(转)

    Profiler React16.5正式在devtool中加入了Profiler功能,用于收集每次变更导致的渲染时间,帮助开发者发现潜在的性能问题,有助于开发更高性能的React应用 官方博客 如何使 ...

  5. [原]openstack-kilo--issue(十三)Unauthorized: The request you have made requires authentication. (HTTP 401) (Request

    在运行nova-list 的时候发现报错401:如下面 ========>>>>>>>>> 正常显示 [root@controller ~]# n ...

  6. mtr

    一般在windows 来判断网络连通性用ping 和tracert,ping的话可以来判断丢包率,tracert可以用来跟踪路由,在Linux中有一个更好的网络连通性判断工具,它可以结合ping ns ...

  7. d3.js 根据需求定制pie图饼图

    参考网址: http://d3pie.org/#generator 用法: 1.在网址中,跟着步骤,设置样式和效果,最后获取pie的option格式 2.引入d3.min.js和d3pie.min.j ...

  8. day_5.27python网络编程

    开始进行python网络编程2018-5-27 20:27:30 Tcp/Ip协议

  9. webpack构建工具快速上手指南

    最近在研究react项目,接触到webpack打包工具.刚接触的时候一脸茫然,经过最近的学习,下面我来带大家开启webpack入门之旅. webpack是什么 webpack是近期最火的一款模块加载器 ...

  10. Linux 磁盘管理命令

    df NO1. 显示所有存储系统空间使用情况,同时显示存储系统的文件系统类型s[root@rehat root]# df -aT NO2. 显示指定文件系统的空间使用情况[root@rehat roo ...