中文 English

How to Install Node-RED with NPM

Published: 2021-02-01
node npm nodejs Node-RED Linux centos os API Low-code browser browser Smart Home Module Flow Flow installation Startup Upgrade

What Is Node-RED

Node-RED is a low-code/no-code programming tool for connecting hardware devices, APIs, and online services in a novel and interesting way. It is especially suitable for smart home scenarios.

Node-RED provides a browser-based flow editor, making it easy to connect various nodes in the panel. You can then deploy the flow to runtime with a single click.

You can use a rich text editor to create JavaScript functions inside the editor. Built-in libraries allow you to save useful functions, templates, or flows for reuse.

Built on Node.js

Built on Node.js, a lightweight runtime that fully leverages an event-driven non-blocking model. This makes it ideal for network edge deployments on low-cost hardware such as Raspberry Pi, as well as cloud servers.

The Node package repository contains more than 225,000 modules, making it easy to expand the panel with new functionality.

Social Sharing

Flows created in Node-RED are stored as JSON, making them easy to import/export and share with others.

The online flow library lets you share great flows with the world.

Install Node and NPM

Install with NPM

To install Node-RED, use the npm command that comes with node.js:

sudo npm install -g --unsafe-perm node-red

This will install Node-RED and its dependencies as a global module. If the end of the output looks like this, it means the installation succeeded:

+ node-red@1.1.0
added 332 packages from 341 contributors in 18.494s
found 0 vulnerabilities

Run Node-RED

After installing it as a global module, you can start Node-RED in the terminal with the node-red command. Use Ctrl-C or close the terminal window to stop it.

$ node-red

Welcome to Node-RED
===================

30 Jun 23:43:39 - [info] Node-RED version: v1.1.0
30 Jun 23:43:39 - [info] Node.js  version: v10.21.0
30 Jun 23:43:39 - [info] Darwin 18.7.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/

Then you can open the editor by visiting http://localhost:1880 in a browser.

The logs provide several kinds of information:

Command Line Usage

You can launch Node-RED with the following command:


node-red [-v] [-?] [--settings settings.js] [--userDir DIR]
         [--port PORT] [--title TITLE] [--safe] [flows.json|projectName]
         [-D X=Y|@file]
Option Description
-p, –port TCP port for runtime listening. Default: 1880
–safe Start Node-RED without running flows. This lets you open and edit flows in the editor without executing them until you deploy.
-s, –settings FILE Specify the settings file to use. Default: <userDir>/settings.js
–title TITLE Set the process window title
-u, –userDir DIR Specify the user directory. Default: ~/.node-red
-v Enable verbose output
-?, –help Show the command-line usage help and exit
flows.json projectName

Node-RED uses flows_<hostname>.json as the default flow file. If the machine’s hostname may change, make sure to provide a static file name, either as a command-line argument or with the flowsFile option in the settings file.

How to Upgrade Node-RED

If Node-RED was installed as a global npm package, you can upgrade it to the latest version with:

sudo npm install -g --unsafe-perm node-red

Reference

Node-RED Node.js Running Node-RED locally