要在本地安装Node-RED,您需要受支持的Node.js版本。
要安装Node-RED,您可以使用node.js自带的npm命令:
sudo npm install -g --unsafe-perm node-red
如果您使用的是Windows系统,请不要以sudo命令开头。
该命令将全局安装Node-RED及其依赖项。
如果命令输出的末尾看起来类似以下内容,则可以确认已成功:
+ node-red@1.1.0
added 332 packages from 341 contributors in 18.494s
found 0 vulnerabilities
要以最简单的方式在Docker中运行,只需执行:
docker run -it -p 1880:1880 --name mynodered nodered/node-red
如需更详细信息,请参阅我们的docker指南。
如果您的操作系统支持 Snap,您可以通过以下方式安装 Node-RED:
sudo snap install node-red
当以Snap包形式安装时,它将在安全容器中运行,该容器无法访问您可能需要使用的一些额外功能,例如:
gcc - 用于编译您想安装节点的任何二进制组件git - 如需使用项目功能则需安装如果您需要访问系统硬件或添加需要编译的节点,我们建议完整安装Node-RED而不要使用snap包。
安装为全局模块后,您可以使用node-red命令在终端中启动Node-RED。您可以使用Ctrl-C或关闭终端窗口来停止Node-RED。
$ node-red
Welcome to Node-RED
===================
30 Jun 23:43:39 - [info] Node-RED version: v1.3.5
30 Jun 23:43:39 - [info] Node.js version: v14.7.2
30 Jun 23:43:39 - [info] Darwin 19.6.0 x64 LE
30 Jun 23:43:39 - [info] Loading palette nodes
30 Jun 23:43:44 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
30 Jun 23:43:44 - [info] Settings file : /Users/nol/.node-red/settings.js
30 Jun 23:43:44 - [info] HTTP Static : /Users/nol/node-red/web
30 Jun 23:43:44 - [info] Context store : 'default' [module=localfilesystem]
30 Jun 23:43:44 - [info] User directory : /Users/nol/.node-red
30 Jun 23:43:44 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
30 Jun 23:43:44 - [info] Creating new flows file : flows_noltop.json
30 Jun 23:43:44 - [info] Starting flows
30 Jun 23:43:44 - [info] Started flows
30 Jun 23:43:44 - [info] Server now running at http://127.0.0.1:1880/red/
然后您可以通过在浏览器中访问 http://localhost:1880 来进入Node-RED编辑器。
日志输出为您提供各种信息片段:
Node-RED默认使用flows_作为流程文件。您可以通过将流程文件名作为参数传递给node-red command来更改此设置。
Node-RED可以通过命令node-red启动。该命令可以接受多种参数:
node-red [-v] [-?] [--settings settings.js] [--userDir DIR]
[--port PORT] [--title TITLE] [--safe] [flows.json|projectName]
[-D X=Y|@file]
| 选项 | 描述 |
|---|---|
-p, --port PORT |
Sets the TCP port the runtime listens on. Default: 1880 |
--safe |
Starts Node-RED without starting the flows. This allows you to open the flows in the editor and make changes without the flows running. When you deploy your changes, the flows are then started. |
-s, --settings FILE |
Sets the settings file to use. Default: settings.js in userDir |
--title TITLE |
Set process window title |
-u, --userDir DIR |
Sets the user directory to use. Default: ~/.node-red |
-v |
Enables verbose output |
-D X=Y|@file |
Override individual settings |
-?, --help |
Shows command-line usage help and exits |
flows.json|projectName |
If the Projects feature is not enabled, this sets the flow file you want to work with. If the Projects feature is enabled, this identifies which project should be started. |
Node-RED默认使用flows_作为流程配置文件。如果运行环境的主机名可能发生变化,您应当指定一个固定的文件名;可以通过命令行参数或在settings file中使用flowsFile选项进行设置。
自 Node-RED 1.1.0 起
您可以使用命令行选项-D(或--define)来覆盖单个设置。
例如,要更改日志记录级别,您可以使用:
-D logging.console.level=trace
您也可以将自定义设置作为文件提供:
-D @./custom-settings.txt
该文件应包含要覆盖的设置列表:
logging.console.level=trace
logging.console.audit=true
在某些情况下,需要向底层的Node.js进程传递参数。例如,在运行于内存受限的设备上时,比如树莓派或BeagleBone Black。
要实现这一点,您必须使用node-red-pi启动脚本来替代node-red。
注意:该脚本在Windows系统上不可用。
另外,如果使用node命令运行Node-RED,必须在指定red.js和要传递给Node-RED本身的参数之前,为node进程提供参数。
以下两个命令展示了这两种方法:
node-red-pi --max-old-space-size=128 --userDir /home/user/node-red-data/
node --max-old-space-size=128 red.js --userDir /home/user/node-red-data/
如果您已将Node-RED作为全局npm包安装,可以通过以下命令升级至最新版本:
sudo npm install -g --unsafe-perm node-red
如果您使用的是Windows系统,请不要以sudo命令开头。
Node-RED: 面向事件驱动应用的低代码编程平台。
版权所有 OpenJS基金会 及 Node-RED 贡献者。保留所有权利。OpenJS基金会 拥有注册商标并使用商标。有关 OpenJS基金会 的商标列表,请参阅我们的 商标政策 和 商标列表。未在 OpenJS基金会商标列表 中标注的商标™或注册®商标归其各自持有人所有。使用这些商标并不意味着与它们有任何关联或获得其认可。
The OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS基金会章程 | 商标政策 | 商标列表 | Cookie政策