最全的Java后端知识体系 https://www.pdai.tech, 每天更新中。
在某个项目中需要调研下node-red的功能,我大概花了三天时间研究了相关的官方文档,写了几个Demo总结了下node-red相关的功能。如需转载,请注明出处 https://www.cnblogs.com/pengdai/p/9143617.html -----2017年12月 @pdai
内容目录
Introduction
Node-RED is a visual tool for wiring the Internet of Things developed by IBM Emerging Technology and the open source community. Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click. Using Node-RED, developers wire up input, output and processing nodes to create flows to process data, control things, or send alerts.
For more details, please check below official site:
https://nodered.org/
Features
Browser-based flow editing
Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range of nodes in the palette. Flows can be then deployed to the runtime in a single-click.
JavaScript functions can be created within the editor using a rich text editor.
A built-in library allows you to save useful functions, templates or flows for re-use.
Built on Node.js
The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-blocking model. This makes it ideal to run at the edge of the network on low-cost hardware such as the Raspberry Pi as well as in the cloud.
With over 225,000 modules in Node’s package repository, it is easy to extend the range of palette nodes to add new capabilities.
Social Development
The flows created in Node-RED are stored using JSON which can be easily imported and exported for sharing with others.
An online flow library allows you to share your best flows with the world.
A first view example
It works by allowing you to wire up web services or custom “nodes” to each other, or to things, to do things like:
- Send an email on a rainy weather forecast.
- Push sensor data to services like Twitter.
- Perform complex analysis on data with ease.
Installation
Install CentOS7
- setup global proxy
- setup yum proxy
- yum update
Install NodeJS
-
Download latest nodejs - https://nodejs.org/en/download/
-
Check this to install - https://www.cnblogs.com/8765h/p/4777746.html
yum install wget
wget https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.xz
tar -xvf node-v8.9.1-linux-x64.tar.xz
ls
cd node-v8.9.1-linux-x64
cd bin
./node -v
Soft link to node and npm:
ln -s /root/node-v8.9.1-linux-x64/bin/npm /usr/local/bin/
ln -s /root/node-v8.9.1-linux-x64/bin/node /usr/local/bin/
Check node command:
node -v
npm -v
Install Node-RED
The easiest way to install Node-RED is to use node’s package manager, npm. Installing it as a global module adds the command node-red to your system path:
sudo npm install -g --unsafe-perm node-red
Got error logs:
npm ERR! code EPROTO
npm ERR! errno EPROTO
npm ERR! request to https://registry.npmjs.org/node-red failed, reason: write EPROTO 139688675866432:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:825:
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-11-20T06_43_01_981Z-debug.log
Check the issue and got this - http://blog.youkuaiyun.com/yypsober/article/details/51906616
So continue to config npm proxy:
npm config set strict-ssl false
npm config set proxy http://10.193.12.222:63128
npm config set https-proxy=https://10.193.12.222:63128
But still got failed.
Then remove the global proxy and then set secure-ssl=false, you can update ~/.npmrc
proxy=http://10.xxx.xxx.xxx:xxxxx/
strict-ssl=false
registry=http://registry.npmjs.org/
Continue to install node-red
[root@node-red ~]# npm install -g --unsafe-perm node-red
npm WARN deprecated i18next-client@1.10.3: you can use npm install i18next from version 2.0.0
npm WARN deprecated nodemailer@1.11.0: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
/root/node-v8.9.1-linux-x64/bin/node-red -> /root/node-v8.9.1-linux-x64/lib/node_modules/_images/node-red/red.js
/root/node-v8.9.1-linux-x64/bin/node-red-pi -> /root/node-v8.9.1-linux-x64/lib/node_modules/_images/node-red/bin/node-red-pi
> bcrypt@1.0.3 install /root/node-v8.9.1-linux-x64/lib/node_modules/_images/node-red/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
[bcrypt] Success: "/root/node-v8.9.1-linux-x64/lib/node_modules/_images/node-red/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote
+ node-red@0.17.5
added 367 packages in 118.79s
Run Node-RED
Run node-RED
[root@node-red ~]# node-red
-bash: node-red: command not found
[root@node-red ~]# cd node-v8.9.1-linux-x64
[root@node-red node-v8.9.1-linux-x64]# ls
bin CHANGELOG.md etc include lib LICENSE README.md share
[root@node-red node-v8.9.1-linux-x64]# cd bin/
[root@node-red bin]# ls
node node-red node-red-pi npm npx
Soft link to node-red:
[root@node-red bin]# ln -s /root/node-v8.9.1-linux-x64/bin/node-red /usr/local/bi