[Node.js] Using npm link to use node modules that are "in progress"
It is some times convenient, even necessary, to make use of a module that you are working on before it has been published to the node package manager (npm). The npm link
command makes this simple.
For example:
upper/index.js:
module.exports = function(str){ return str.toUpperCase(); }
packjson:
{ "name": "upper", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
user/index.js:
var upper = require('upper'); console.log(upper('hello world'));
In the user/index.js, we want to use upper module which is not published to the npm yet. Therefore, when we run the app, it will report the error:
Enable to test the module, we can use 'npm link':
- Locate upper folder and run:
npm link
It says that our node_modules links to this upper module.
[Notice:] You need to have package.json file when using 'npm link', because it uses its name to refering the module.
2. Go back to the user dir, use that upper dir:
cd ../user
npm link upper
C:\Users\Answer1215\WebstormProjects\mean\npmlink\user\node_modules\upper -> C:\Users\Answer1215\AppData\Roaming\npm\node_modules\upper -> C:\Users\Answer1215\WebstormProjects\mean\n
pmlink\upper
It says that, our upper dir links to the system node_module's upper, then links to our user dir.
3. Now we can use this upper module.
[Notice:] Once you finish testing, you need to unlink this moduole! or it may cause problem
4. In the user dir:
npm unlink upper
More:
https://egghead.io/lessons/node-js-using-npm-link-to-use-node-modules-that-are-in-progress
相关文章
- js 实现快速排序
- js书写原生ajax,JS 原生ajax写法
- html如何只刷新页面指定,js控制页面刷新 JS刷新当前页面的几种方法总结
- node.js(5) MySQL数据库的学习
- 【说站】js有哪些常用的数组api
- js中四舍五入的方法_JS取整
- Vue.js – 引入外部 JS 文件
- 开心档之Vue.js 样式绑定
- 利用js实现不同域名显示不同备案的方法
- Node.js 软件包管理工具 (npm)
- Linux 安装node.js和npm教程详解程序员
- JS将数字转换成三位逗号分隔的样式详解编程语言
- Node.js读写文件详解编程语言
- JS动态引入js、CSS动态创建script/link/style标签详解编程语言
- 使用Node.js连接MySQL数据库(node-mysql)
- 使用JS连接MySQL数据库:实现化繁为简(js连接mysql数据库)
- 使用 JS 操作 Redis:实现强大数据存储.(js调用redis)
- JS实时链接Oracle让数据库访问更便捷(js实时连接oracle)
- 使用Oracle和JS开发新一代应用仿真世界(oracle js)
- 用XML+FSO+JS实现服务器端文件的
- 非常不错的[JS]Cookie精通之路
- js获取坐标通过JS得到当前焦点(鼠标)的坐标属性
- 图片放大镜jquery.jqzoom.js使用实例附放大镜图标
- node.js使用npm安装插件时提示installError:ENOENT报错的解决方法
- 我的Node.js学习之路(二)NPM模块管理
- Node.js安装教程和NPM包管理器使用详解