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':

  1. 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"的更多相关文章

  1. 如何在CentOS 7上安装Node.js和npm

    Node.js是一个跨平台的JavaScript运行时环境,允许在服务器端执行JavaScript代码.Node.js主要用于后端,但也作为全栈和前端解决方案而流行. npm,Node软件包管理器的缩 ...

  2. node.js的npm详解

    一.什么是npm呢 npm(Node Package Manager,node包管理器)是node的包管理器,他允许开发人员在node.js应用程序中创建,共享并重用模块.模块就是可以在不同的项目中重 ...

  3. 安装node.js 和 npm 的完整步骤

    vue 生命周期 1,beforeCreate 组件刚刚被创建 2,created 组件创建完成 3,beforeMount 挂载之前 4,mounted 挂载之后 5,beforeDestory 组 ...

  4. Windwos安装Node.js和npm的详细步骤

    How to Install Node.js and NPM on Windows Node.js和npm 安装 Node.js 的时候会自动安装 npm ,并且 npm 就是 Node.js 的包管 ...

  5. 在Linux Mint上安装node.js和npm

    1.安装Node.js 前端开发过程中,很多项目使用npm的http-server的模块来运行一个静态的服务器,我个人在Dell的笔记本上安装的是Linux Mint最新版本,所以想尝试一下在Linu ...

  6. 关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用

    关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用   工作环境:window下 在一切的最开始,安装node.js (中文站,更新比较慢http://nodejs.cn/) ...

  7. node.js的npm安装

    我不打算引进node.js的npm安装,但发现node.js通过管理一些包npm实现,或给一个简短的npm. 1.npm什么        npm是一个node包管理和分发工具,已经成为了非官方的公布 ...

  8. Node.js入门 NPM

    参考一 Node入门  七天学会NodeJS  Node.js v4.2.4 手册 & 文档  Node.js 教程 node.js摸石头系列 从零开始学习node.js   What is ...

  9. Node.js、npm、vue-cli 的安装配置环境变量

    我安装node.js是为了学习vue,需要用到npm,所以就把node.js安装了,安装node.js会带有npm的安装. 在安装node.js之前,我们需要了解以下三个内容. npm: Nodejs ...

随机推荐

  1. bzoj4009

    这是一道神题,首先我们不难先到整体二分吧 下面的问题就是,求出对于每个水果,有多少盘子是他的子路径 直接考虑不是很容易,我们换个思路,考虑对于每个盘子,哪些水果能包含它 我们假设盘子a,b,dep[a ...

  2. php简单实现MVC

    在PHP中使用MVC越来越流行了,特别是在一些开源的框架当中.MVC足以应对大多数的情况,但还有一些情况是其不太适合的,如比较简单的个人博客,对于只有几百篇文章量级的博客,使用MVC让人觉得有些太复杂 ...

  3. Java [Leetcode 292]Nim Game

    问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...

  4. memcache 存储单个KEY,数据量过大的时候性能慢!以及简单的memcache不适合用到的场景

    今天有人问到我:memcache存储大数据量,10K,100K,1M的时候,效果怎么样??我回答:不好,效果非常慢.对方问:为什么啊??我回答不上来...于是就找了点资料. memcached使用需要 ...

  5. 《深入Java虚拟机学习笔记》- 第14章 浮点运算

    <深入Java虚拟机学习笔记>- 第13章 浮点运算

  6. alibaba笔试1

    5.D 一个线程不可以改变另一个线程的程序计数器.如果改变了,线程在切换后就恢复不到正确的位置. 一个线程可以访问另一个线程的栈.http://bbs.csdn.net/topics/39008942 ...

  7. Live555研究之二Sleep实现

    Live555通过一个while循环来不断读取socket,判断是否有连接进来,但是Live555并没有使用Sleep函数来让线程休眠多少毫秒来降低CPU占用率.Live555是通过select函数来 ...

  8. ubuntu12.04 安装 chrome

    1.下载deb包 2. sudo apt-get remove google-chrome-stable sudo dpkg -i google-chrome-stable_current_amd64 ...

  9. 第一个GTK+程序

    在这一章节中,我们将开始编写第一个GTK+程序. 超级简单的例子 我们要“制造”一个超级简单的GTK+程序.就是显示一个空白的窗口. #include <gtk/gtk.h> int ma ...

  10. ADB Server Didn’t ACK ,failed to Start Daemon 解决方法

    解决方法如下: 1.adb nodaemon server 查看不能执行的原因,输出: cannot bind ‘tcp:5037’ 2.定位到了是端口的问题!是5037端口被占用了! 3.netst ...