Home Assistant build log - install NodeRed

Tutorial list

Home Assistant set up log (I) - install raspberry pie system
Home Assistant set up log (2) - configure raspberry pie system
Home Assistant build log (3) - install and start Home Assistant
Home Assistant set up logs (IV) - accessing Home Assistant on the Internet
Home Assistant set up a log (5) - let Bluetooth speakers sing
Home Assistant building log (VI) - MPD player
Home Assistant build log (7) - install NodeRed

The easiest way to install NodeRed is to use apt directly. However, there will be a problem. When installing NodeRed, you need to rely on NodeJS and NPM. In the current buster source, NodeJS is 10.15.2~dfsg-2+rpi1, and NPM is 5.8.0+ds6-4. These two versions are not fully compatible, so you will always be warned when using NP There are some errors in M install. For example, in the installation NeteaseCloudMusicApi It's been a failure.
Although NPM can be upgraded to the new version by the command npm install -g npm, the previous apt installed NPM in / usr/bin, and the upgrade command installed NPM in / usr/local/bin. As a result, there are two versions of NPM at the same time, and the system will use NPM for a long time by default. Now try some unconventional installation methods to see if there will be some magical problems in the future.

1. View the software source manually

Once, I was curious to see whether NPM 5.8.0+ds6-4 was the only version in the software source.
Software source location of NPM installation package
Other NPM versions found

But you can only find 5.8.0+ds6-4 in apt-cache

pi@pi:~ $ apt-cache show npm
Package: npm
Version: 5.8.0+ds6-4
Installed-Size: 8439
Maintainer: Debian Javascript Maintainers <pkg-javascript-devel@lists.alioth.debian.org>
Architecture: all
Depends: nodejs (>= 6.11~), ca-certificates, node-abbrev (>= 1.1.1~), node-ansi-regex (>= 3.0~), node-ansistyles (>= 0.1.3~), node-aproba (>= 1.2~), node-archy (>= 1.0~), node-cacache (>= 10.0.4~), node-bluebird (>= 3.5.1~), node-call-limit (>= 1.1~), node-chownr (>= 1.0.1~), node-config-chain (>= 1.1.11~), node-detect-indent (>= 5.0~), node-detect-newline (>= 2.1~), node-editor (>= 1.0~), node-fs-vacuum (>= 1.2.10~), node-fs-write-stream-atomic (>= 1.0.10~), node-glob (>= 7.1.2~), node-graceful-fs (>= 4.1.11~), node-has-unicode (>= 2.0.1~), node-hosted-git-info (>= 2.6~), node-iferr (>= 0.1.5~), node-inflight (>= 1.0.6~), node-inherits (>= 2.0.3~), node-ini (>= 1.3.5~), node-npm-package-arg, node-promzard, node-jsonstream (>= 1.3.2~), node-json-parse-better-errors (>= 1.0.1~), node-lazy-property (>= 1.0~), node-libnpx (>= 10.0.1~), node-lockfile (>= 1.0.3~), node-lru-cache (>= 4.1.1~), node-mississippi (>= 3.0~), node-mkdirp (>= 0.3.3), node-move-concurrently (>= 1.0.1~), node-nopt, node-normalize-package-data (>= 2.4~), node-gyp (>= 3.6.2~), node-resolve-from (>= 4.0~), node-encoding, node-errno, node-npmlog (>= 4.1.2~), node-once (>= 1.4~), node-opener (>= 1.4.3~), node-osenv (>= 0.1.5~), node-path-is-inside (>= 1.0.2~), node-promise-inflight (>= 1.0.1~), node-ansi, node-qw (>= 1.0.1~), node-read (>= 1.0.7~), node-read-package-json (>= 2.0.13~), node-request (>= 2.83~), node-retry (>= 0.10.1~), node-rimraf (>= 2.6.2~), node-safe-buffer (>= 5.1.1~), node-semver (>= 5.5~), node-sha (>= 2.0.1~), node-slide (>= 1.1.6~), node-sorted-object (>= 2.0.1~), node-from2, node-stream-iterate, node-ssri (>= 5.2.4~), node-strip-ansi (>= 4.0~), node-tar (>= 4.4~), node-text-table (>= 0.2~), node-uid-number (>= 0.0.6~), node-unique-filename (>= 1.1~), node-unpipe (>= 1.0~), node-boxen (>= 1.2.1~), node-import-lazy, node-is-npm (>= 1.0~), node-latest-version (>= 3.0~), node-semver-diff (>= 2.0~), node-xdg-basedir (>= 3.0~), node-validate-npm-package-name (>= 3.0~), node-which (>= 1.3~), node-wrappy (>= 1.0.2~), node-write-file-atomic (>= 2.3~)
Size: 1016092
SHA256: 47e13b69e221046fcba1eced1f8474937729012d223e046620cf18455e3d13b4
SHA1: b62536f17ad1b6c1fe4b2f808c1a92d479590033
MD5sum: 83302ec272e96d5ffe53f06e3dd2863c
Description: package manager for Node.js
 Node.js is an event-based server-side javascript engine.
 .
 npm is the package manager for the Node JavaScript platform.  It puts
 modules in place so that node can find them, and manages dependency
 conflicts intelligently.
 .
 It is extremely configurable to support a wide variety of use cases.
 Most commonly, it is used to publish, discover, install, and develop
 node programs.
Description-md5: 85ba8bf129c09297837a706dcf08eb1f
Homepage: https://docs.npmjs.com/
Section: web
Priority: optional
Filename: pool/main/n/npm/npm_5.8.0+ds6-4_all.deb

Then I checked it in Baidu and found such a web page
https://packages.debian.org/bullseye/npm
It can be seen that NPM of 6.13.4+ds-2 can be downloaded in the bullseye release, and only 5.8.0+ds6-4 can be downloaded in the buster release. If I directly change the download source to the bullseye release, can I download NPM 6.13.4+ds-2? Try it.

2. Replace the software source

sudo vi /etc/apt/source.list
# Put the old one
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib

=>

# Replace with a new one
deb http://mirrors.aliyun.com/raspbian/raspbian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ bullseye main non-free contrib

Update the software source

sudo apt-get update

View the version of NPM

pi@pi:~ $ apt-cache show npm
Package: npm
Version: 6.13.4+ds-2
Installed-Size: 3412
Maintainer: Debian Javascript Maintainers <pkg-javascript-devel@lists.alioth.debian.org>
Architecture: all
Depends: nodejs (>= 6.11~), ca-certificates, node-abbrev (>= 1.1.1~), node-ajv, node-ansi, node-ansi-regex (>= 3.0~), node-ansi-styles, node-ansistyles, node-aproba, node-archy (>= 1.0~), node-are-we-there-yet, node-asap, node-asn1, node-assert-plus, node-asynckit, node-aws4, node-aws-sign2, node-balanced-match, node-bcrypt-pbkdf, node-bl, node-bluebird, node-boxen, node-brace-expansion, node-builtin-modules, node-builtins, node-cacache, node-call-limit, node-camelcase, node-caseless, node-chalk, node-chownr, node-ci-info, node-cli-boxes, node-cliui, node-clone, node-co, node-color-convert, node-color-name, node-colors, node-columnify, node-combined-stream, node-concat-map, node-concat-stream, node-config-chain, node-configstore, node-console-control-strings, node-copy-concurrently, node-core-util-is, node-cross-spawn, node-crypto-random-string, node-cyclist, node-dashdash, node-debug, node-decamelize, node-deep-extend, node-defaults, node-define-properties, node-delayed-stream, node-delegates, node-detect-indent, node-detect-newline, node-dot-prop, node-duplexer3, node-duplexify, node-ecc-jsbn, node-editor, node-encoding, node-end-of-stream, node-err-code, node-errno, node-es6-promise, node-escape-string-regexp, node-execa, node-extend, node-extsprintf, node-fast-deep-equal, node-find-up, node-flush-write-stream, node-forever-agent, node-form-data, node-from2, node-fs.realpath, node-fs-vacuum, node-fs-write-stream-atomic, node-function-bind, node-gauge, node-genfun, node-get-caller-file, node-getpass, node-glob (>= 7.1.2~), node-got, node-graceful-fs (>= 4.1.11~), node-gyp (>= 3.6.2~), node-har-schema, node-har-validator, node-has-flag, node-has-unicode, node-hosted-git-info (>= 2.6~), node-http-signature, node-iconv-lite, node-iferr, node-import-lazy, node-imurmurhash, node-inflight, node-inherits (>= 2.0.3~), node-ini (>= 1.3.5~), node-invert-kv, node-ip, node-ip-regex, node-isarray, node-isexe, node-is-npm, node-is-obj, node-is-path-inside, node-is-retry-allowed, node-is-stream, node-isstream, node-is-typedarray, node-jsbn, node-jsonparse, node-json-parse-better-errors, node-json-schema, node-json-schema-traverse, node-jsonstream (>= 1.3.2~), node-json-stringify-safe, node-jsprim, node-latest-version, node-lazy-property, node-lcid, node-libnpx, node-locate-path, node-lodash, node-lockfile (>= 1.0.3~), node-lowercase-keys, node-lru-cache (>= 4.1.1~), node-make-dir, node-mem, node-mime, node-mime-types, node-mimic-fn, node-minimatch, node-minimist, node-mississippi, node-mkdirp (>= 0.5.1~), node-move-concurrently, node-ms, node-mute-stream, node-nopt, node-normalize-package-data (>= 2.4~), node-npm-bundled, node-npm-package-arg (>= 6.1.1), node-npmlog (>= 4.1.2~), node-number-is-nan, node-oauth-sign, node-object-assign, node-once (>= 1.4~), node-opener, node-osenv (>= 0.1.5~), node-os-locale, node-os-tmpdir, node-package-json, node-parallel-transform, node-path-exists, node-path-is-absolute, node-path-is-inside, node-promise-inflight, node-promise-retry, node-promzard, node-performance-now, node-p-finally, node-pify, node-p-limit, node-p-locate, node-prepend-http, node-process-nextick-args, node-proto-list, node-prr, node-pseudomap, node-psl, node-pump, node-pumpify, node-punycode, node-qs, node-qw, node-rc, node-read (>= 1.0.7~), node-readable-stream, node-read-package-json (>= 2.0.13~), node-registry-auth-token, node-registry-url, node-request (>= 2.83~), node-require-main-filename, node-require-directory, node-resolve-from (>= 4.0~), node-retry (>= 0.10.1~), node-rimraf (>= 2.6.2~), node-run-queue, node-safe-buffer, node-semver (>= 5.5~), node-set-blocking, node-sha (>= 2.0.1~), node-shebang-command, node-shebang-regex, node-signal-exit, node-slide (>= 1.1.6~), node-sorted-object, node-slash, node-semver-diff, node-spdx-correct, node-spdx-exceptions, node-spdx-expression-parse, node-spdx-license-ids, node-sshpk, node-ssri, node-stream-each, node-stream-iterate, node-stream-shift, node-strict-uri-encode, node-string-decoder, node-string-width, node-strip-ansi (>= 4.0~), node-strip-json-comments, node-strip-eof, node-supports-color, node-tar (>= 4.4~), node-term-size, node-text-table, node-through, node-through2, node-timed-out, node-tough-cookie, node-tunnel-agent, node-tweetnacl, node-typedarray, node-uid-number, node-unique-filename, node-unique-string, node-unpipe, node-url-parse-lax, node-util-deprecate, node-uuid, node-validate-npm-package-name, node-verror, node-which (>= 1.3~), node-which-module, node-wide-align, node-widest-line, node-wrap-ansi, node-wrappy, node-wcwidth.js, node-write-file-atomic, node-xdg-basedir, node-xtend, node-yargs, node-yargs-parser, node-yallist, node-y18n
Size: 646912
SHA256: 00aba43c95437be619d5a94d138774f06aa866f972e2ddcfb10e07eb6a823aed
SHA1: e94e4f762a069060a29a19eed339f05f9f454c8d
MD5sum: 046c392aaaaf8e6008549b4cfc9d9630
Description: package manager for Node.js
 Node.js is an event-based server-side javascript engine.
 .
 npm is the package manager for the Node JavaScript platform.  It puts
 modules in place so that node can find them, and manages dependency
 conflicts intelligently.
 .
 It is extremely configurable to support a wide variety of use cases.
 Most commonly, it is used to publish, discover, install, and develop
 node programs.
Description-md5: 85ba8bf129c09297837a706dcf08eb1f
Homepage: https://docs.npmjs.com/
Section: web
Priority: optional
Filename: pool/main/n/npm/npm_6.13.4+ds-2_all.deb

You can see that the version is 6.13.4+ds-2

3. Install NodeRed

Since NPM can download version 6.13.4+ds-2, try installing NodeRed directly

sudo apt-get install nodered

Then a pop-up came up during the installation, which scared Q to death

Google translate, it means that some services have been updated, and those services need to be restarted, then Yes.
Then the installation is done directly.

Remember to replace the software source from bullseye to buster, and then update the software source

4. Start NodeRed

sudo systemctl start nodered.service

# View running status
systemctl status nodered.service

# Once sent to the soul, it is directly successful. Set the power on and start automatically
sudo systemctl enable nodered.service

5. Modify NodeRed configuration

vi ~/.node-red/settings.js
  1. Convention modify binding port
    # find
    uiPort: process.env.PORT || 1880,
    
    # Change to (be careful not to kill the last comma,)
    uiPort: process.env.PORT || New port,
    
  2. Account password for entering the webpage
    No account password is required to enter the web page, and you can directly enter NodeRed's workbench
    First, install an encryption library bcryptjs to generate passwords
    npm install bcryptjs
    
    Then find the adminAuth module in the configuration file, remove the comments of the whole module, and edit the contents:
    adminAuth: {
    	type: "credentials",
    	users: [{
        	username: "The user name you want",
        	password: "Encrypted password",
        	permissions: "*"
    	}]
    },
    
    Use the following command to generate an encrypted password, such as 123456
    node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" 123456
    
    Generate encrypted password
    $2a$08$2Jq.v9vMdmDmA6issbvRqO/OkNLXT8mH01BdkuYSWwGJI.Gwk/A9.
    
    Paste this string into the encrypted password configured above, and you can log in to NodeRed console through user name and 123456. Of course, restart the service first.
    sudo systemctl restart nodered.service 
    

After configuration, the next chapter attempts to create a process to control the components of HA with NodeRed (it seems that there is only MPD now).

Published 6 original articles, won praise 0, visited 214
Private letter follow

Tags: npm JSON Javascript sudo

Posted on Mon, 10 Feb 2020 02:20:04 -0800 by iceblossom