Skip to content

Commit 2e7da3a

Browse files
author
Dave Conway-Jones
committed
Update writing-functions.md
1 parent c891b9b commit 2e7da3a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

docs/user-guide/writing-functions.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ for example the HTTP In/Response flow requires the <code>msg.req</code> and
4646
nodes <em>should</em> return the message object they were passed having made any
4747
changes to its properties.</div>
4848

49+
Use node.warn() to show warnings in the sidebar to help you debug. For example:
50+
51+
{% highlight javascript %}
52+
node.warn("my var xyz = " + xyz);
53+
{% endhighlight %}
54+
55+
See logging section below for more details.
56+
4957
### Multiple Outputs
5058

5159
The function edit dialog allows the number of outputs to be changed. If there
@@ -121,7 +129,7 @@ doSomeAsyncWork(msg, function(result) {
121129
return;
122130
{% endhighlight %}
123131

124-
**Since Node-RED 1.0**
132+
*Since Node-RED 1.0*
125133

126134
The Function node will clone every message object you pass to `node.send` to
127135
ensure there is no unintended modification of message objects that get reused
@@ -139,7 +147,7 @@ node.send(msg,false);
139147

140148
#### Finishing with a message
141149

142-
**Since Node-RED 1.0**
150+
*Since Node-RED 1.0*
143151

144152
If a Function node does asynchronous work with a message, the runtime will not
145153
automatically know when it has finished handling the message.
@@ -190,7 +198,6 @@ node.on('close', function() {
190198
});
191199
{% endhighlight %}
192200

193-
194201
Or, *since Node-RED 1.1.0*, you can add code to the `Close` tab in the node's edit
195202
dialog.
196203

@@ -204,7 +211,11 @@ node.warn("Something happened you should know about");
204211
node.error("Oh no, something bad happened");
205212
{% endhighlight %}
206213

207-
The `warn` and `error` messages also get sent to the flow editor debug tab.
214+
Where the console output appears will depend on how your opearting sustem and how you start Node-RED.
215+
If you start using a command line - that is the console where logging will appear. If you run as a
216+
system service then it may appear in the system log. If you run under an app like PM2 it will have it's own way for showing logs. On a Pi the install script adds a `node-red-log` command that will display the log.
217+
218+
The `warn` and `error` messages also get sent to the debug tab on the right side of the flow editor.
208219

209220
For finer grained logging, `node.trace()` and `node.debug()` are also available.
210221
If there is no logger configured to capture those levels, they will not be seen.
@@ -446,7 +457,7 @@ The following objects are available within the Function node.
446457
* `global.keys(..)` : return a list of all global-scoped context property keys
447458

448459
#### `RED`
449-
* `RED.util.cloneMessage(..)` : safely clones a message object so it can be reused
460+
* `RED.util.cloneMessage(..)` : safely clones a message object so it can be reused
450461

451462
#### `env`
452463
* `env.get(..)` : get an environment variable

0 commit comments

Comments
 (0)