Using local node for development & testing

I wanted to make a small change to the "Smooth" node, so I forked node-red-nodes on GitHub and checked out my fork to a local directory. I had installed NodeJS on my development machine (Devuan ASCII) with sudo apt-get install -t ascii-backports npm to end up with npm 5.8.0 and NodeJS 8.11.1, then installed Node-RED with sudo npm install -g --unsafe-perm node-red, giving me Node-RED 0.20.7. I then linked my local copy of node-red-nodes by executing sudo npm link ../Sources/node-red-nodes/ in my ~/.node-red directory. This seemed to work (although did result in a few vulnerability warnings for some of node-red-nodes' dependencies), but after restarting Node-RED I still cannot find the "Smooth" node in the list.

TL;DR: How should I set up my Node-RED instance for local development and testing of a module like node-red-nodes?

Edit: Hmm. npm link didn't do what I expected here; the symlink doesn't point to my development copy of node-red-nodes, but rather

$ ls -la ~/.node-red/node_modules
lrwxrwxrwx 1 root root   53 Sep  5 22:37 node-red-nodes -> ../../../../usr/local/lib/node_modules/node-red-nodes

That's no good.

1 Like

Hi @clickworkorange

the node-red-nodes repo contains many nodes, it is not a module you use npm link with at its top level.

You can use the npm link from within the smooth node's own subdirectory - in this instance node-red-nodes/function/smooth

1 Like

Ah. That makes sense, thanks. But how do I make npm link symlink to my development directory rather than try to copy it to /usr/local/lib/node_modules/?

Edit: Hang on, maybe that's a symlink too... wheels within wheels...
Edit: Yep, symlink to symlink

/home/me/.node-red/node_modules/node-red-node-smooth -> /usr/local/lib/node_modules/node-red-node-smooth -> /home/me/Sources/node-red-nodes/function/smooth

We are cooking with gas.

Depending on your version of npm (ie 5.x or later... preferably 6.x), then rather than use npm link you could do:

cd ~/.node-red/
npm install /full/path/to/node-red-nodes/function/smooth

and it will do the Right Thing

That saves polluting your global npm space as well.

3 Likes