[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
[Node.js] Using npm link to use node modules that are "in progress"的更多相关文章
- 如何在CentOS 7上安装Node.js和npm
Node.js是一个跨平台的JavaScript运行时环境,允许在服务器端执行JavaScript代码.Node.js主要用于后端,但也作为全栈和前端解决方案而流行. npm,Node软件包管理器的缩 ...
- node.js的npm详解
一.什么是npm呢 npm(Node Package Manager,node包管理器)是node的包管理器,他允许开发人员在node.js应用程序中创建,共享并重用模块.模块就是可以在不同的项目中重 ...
- 安装node.js 和 npm 的完整步骤
vue 生命周期 1,beforeCreate 组件刚刚被创建 2,created 组件创建完成 3,beforeMount 挂载之前 4,mounted 挂载之后 5,beforeDestory 组 ...
- Windwos安装Node.js和npm的详细步骤
How to Install Node.js and NPM on Windows Node.js和npm 安装 Node.js 的时候会自动安装 npm ,并且 npm 就是 Node.js 的包管 ...
- 在Linux Mint上安装node.js和npm
1.安装Node.js 前端开发过程中,很多项目使用npm的http-server的模块来运行一个静态的服务器,我个人在Dell的笔记本上安装的是Linux Mint最新版本,所以想尝试一下在Linu ...
- 关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用
关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用 工作环境:window下 在一切的最开始,安装node.js (中文站,更新比较慢http://nodejs.cn/) ...
- node.js的npm安装
我不打算引进node.js的npm安装,但发现node.js通过管理一些包npm实现,或给一个简短的npm. 1.npm什么 npm是一个node包管理和分发工具,已经成为了非官方的公布 ...
- Node.js入门 NPM
参考一 Node入门 七天学会NodeJS Node.js v4.2.4 手册 & 文档 Node.js 教程 node.js摸石头系列 从零开始学习node.js What is ...
- Node.js、npm、vue-cli 的安装配置环境变量
我安装node.js是为了学习vue,需要用到npm,所以就把node.js安装了,安装node.js会带有npm的安装. 在安装node.js之前,我们需要了解以下三个内容. npm: Nodejs ...
随机推荐
- hdu 3033 I love sneakers!
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- How to cancel parallel loops in .NET C# z
Cancellation token Parallel options CancellationTokenSource cancellationTokenSource = new Cancellati ...
- 29、activity横竖屏切换细节问题
1 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import andro ...
- HDU 4825-Xor Sum(trie)
题意: 给你一组数,开始询问给一个数 求组中与该数异或值最大的数. 分析:根据异或的特点 要想得到的异或值最大 尽可能的让两个数的每位都相反 先把给定的一组数建树,数的最后一位对应的节点保存这个数的 ...
- 【译】 AWK教程指南 附录E-正则表达式
为什么要使用正则表达式 UNIX 中提供了许多 指令 和 tools,它们具有在文件中 查找(Search)字串或替换(Replace)字串 的功能.像 grep, vi , sed, awk,... ...
- .net之单元测试
一.单元测试的目的是为了提高项目的质量 二..net单元测试的实施步骤是:在已经创建的类文件的某个方法上右键-->选择创建单元测试-->系统会创建单元测试解决方案--->单元测试解决 ...
- ruby 资料整理
http://blog.csdn.net/maingalaxy/article/details/46013393 http://blog.csdn.net/dzl84394/article/detai ...
- Python引用传值总结
Python函数的参数传值使用的是引用传值,也就是说传的是参数的内存地址值,因此在函数中改变参数的值,函数外也会改变. 这里需要注意的是如果传的参数类型是不可改变的,如String类型.元组类型,函数 ...
- HW6.28
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- JAVA中关于Map的九大问题
通常来说,Map是一个由键值对组成的数据结构,且在集合中每个键是唯一的.下面就以K和V来代表键和值,来说明一下java中关于Map的九大问题. 0.将Map转换为List类型 在java中Map接口提 ...