Skip to content

Commit af802f5

Browse files
committed
use npm install <folder> to test with npm 5, minor edits
1 parent dd18070 commit af802f5

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

docs/creating-nodes/first-node.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ title: Creating your first node
77
Nodes get created when a flow is deployed, they may send and receive some messages
88
whilst the flow is running and they get deleted when the next flow is deployed.
99

10-
They consist of a pair of files; a JavaScript file that defines what the
10+
They typically consist of a pair of files; a JavaScript file that defines what the
1111
node does, and an html file that defines the node's properties, edit dialog and
1212
help text.
1313

14-
When packaged as an npm module, a `package.json` file is used to pull it all together.
14+
A `package.json` file is used to package it all together as an npm module.
1515

1616
- [Creating a simple node](#creating-a-simple-node)
1717
- [package.json](#package-json)
@@ -25,6 +25,8 @@ When packaged as an npm module, a `package.json` file is used to pull it all tog
2525
This example will show how to create a node that converts message payloads to
2626
all lower-case characters.
2727

28+
Ensure you have the recommended LTS version of Node.js installed on your system. As of this writing this is version **LTS 8.x** which includes npm version 5.x.
29+
2830
Create a directory where you will develop your code. Within that directory,
2931
create the following files:
3032

@@ -149,16 +151,27 @@ For more information about the editor part of the node, see [here](node-html).
149151

150152
### Testing your node in Node-RED
151153

152-
Once you have created a basic node module as described above, you can install
153-
it into your Node-RED runtime.
154+
Once you have created a basic node module as described above, you can install it into your Node-RED runtime.
155+
156+
To test a node module locally using npm 5.x, the [`npm install <folder>`](https://docs.npmjs.com/cli/install) command can be used. This allows you
157+
to develop the node in a local directory and have it linked into a local node-red install during development.
158+
159+
In your node-red user directory, typically `~/.node-red`, run:
160+
161+
npm install <location of node module>
162+
163+
For example, if your node is located at `~/dev/node-red-contrib-example-lower-case` you would type the following:
164+
165+
cd ~/.node-red
166+
npm install ~/dev/node-red-contrib-example-lower-case
167+
168+
This creates a symbolic link to your node module project directory in `~/.node-red/node_modules` so that Node-RED will discover the node when it starts. Any changes to the node's file can be picked up by simply restarting Node-RED.
154169

155-
To test a node module locally, the `npm link` command can be used. This allows you
156-
to develop the node in a local directory and have it linked into a local node-red
157-
install, as if it had been npm installed.
170+
If you are using an older version of npm, you can create a symbolic link manually to your project. To do so:
158171

159-
1. in the directory containing the node's `package.json` file, run: `sudo npm link`.
160-
2. in your node-red user directory, typically `~/.node-red` run: `npm link <name of node module>`.
172+
cd ~/.node-red/node_modules
173+
ln -s ~/dev/node-red-contrib-example-lower-case .
161174

162-
This creates the appropriate symbolic links between the two directories so Node-RED
163-
will discover the node when it starts. Any changes to the node's file can be picked
164-
up by simply restarting Node-RED.
175+
<div class="doc-callout">
176+
<em>Note</em>: npm 5 will add your module as a dependency in the <code>package.json</code> file located in your user directory. To prevent this, use the npm <code>--no-save</code> option.
177+
</div>

0 commit comments

Comments
 (0)