2 * Copyright 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // If you use this as a template, update the copyright with your own name.
19 // Sample Node-RED node file
22 module.exports = function(RED) {
24 // require any external libraries we may need....
25 //var foo = require("foo-library");
27 // The main node definition - most things happen in here
28 function SampleNode(n) {
30 RED.nodes.createNode(this,n);
32 // Store local copies of the node configuration (as defined in the .html)
35 // Do whatever you need to do in here - declare callbacks etc
36 // Note: this sample doesn't do anything much - it will only send
37 // this message once at startup...
38 // Look at other real nodes for some better ideas of what to do....
40 msg.topic = this.topic;
41 msg.payload = "Hello world !"
43 // send out the message to the rest of the workspace.
46 // respond to inputs....
47 this.on('input', function (msg) {
48 node.warn("I saw a payload: "+msg.payload);
49 // in this example just send it straight on... should process it here really
53 this.on("close", function() {
54 // Called when the node is shutdown - eg on redeploy.
55 // Allows ports to be closed, connections dropped etc.
56 // eg: this.client.disconnect();
60 // Register the node by name. This must be called before overriding any of the
62 RED.nodes.registerType("sample",SampleNode);