Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qnimbus/node-red-development
Development environment for NodeRED
https://github.com/qnimbus/node-red-development
Last synced: about 1 month ago
JSON representation
Development environment for NodeRED
- Host: GitHub
- URL: https://github.com/qnimbus/node-red-development
- Owner: QNimbus
- License: mit
- Created: 2020-01-31T16:55:52.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T22:52:31.000Z (about 2 years ago)
- Last Synced: 2023-04-07T01:16:17.866Z (almost 2 years ago)
- Language: JavaScript
- Size: 240 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-red-development
A simple and embedded NodeRED setup for easy Node development
## Table of contents
- [Table of contents](#table-of-contents)
- [Release Notes](#release-notes)
- [v0.1.1](#v011)
- [v0.1.0](#v010)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [VSCode](#vscode)
- [Linters](#linters)
- [Logger](#logger)
- [Files](#files)
- [**package.json**](#packagejson)
- [**settings.js**](#settingsjs)
- [**server.js**](#serverjs)
- [Enabling HTTPS](#enabling-https)
- [Enabling User authentication](#enabling-user-authentication)
- [Securing http-in endpoints](#securing-http-in-endpoints)
- [Allow access from other networks than localhost](#allow-access-from-other-networks-than-localhost)
- [Installing NodeRED nodes](#installing-nodered-nodes)
- [NPM Scripts](#npm-scripts)
- [Security](#security)
- [TL;DR](#tldr)
- [To do](#to-do)## Release Notes
### v0.1.1
- Added VSCode task to enable Prettier for node_modules that are symlinked (`yarn link`). This task can optionally be run as a `preLaunchTask` for debugging.
- Added `.prettierignore` file with basic configuration.
- Added description about how to add a git submodule in the [Installing NodeRED nodes](#installing-nodered-nodes) section.
- Added `local_modules` to `.gitignore` file.
- Added a [TL;DR](#tldr) section with a guick install guide of sorts.### v0.1.0
- Initial release
## Prerequisites
This project uses `yarn` for package management. Alternatively you can use `npm` buy `yarn` is preferred.
To install yarn:
> \$ npm install yarn --global
## Installation
```sh
# Clone this repository into the project folder
$ git clone https://github.com/QNimbus/node-red-development.git
# Install the package dependencies
$ yarn install
# To start the NodeRED server
$ yarn start
```## Configuration
The most relevant configuration settings can be setup within the _config_ section of `package.json`. If not set, the default values are used or may be overridden by environment variables. The node-red specific settings are contained in `settings.js`.
This template project is pre-configured with the following default configuration:
- The default protocol is HTTP
- The default port is 1880
- The default _User folder_ is `./.nodered`
- The default _Flows_ file is `./flows.json`
- The default static web folder is `./public`
- The default URI is `/`
- The default admin URI is `/admin`
- Logging is set to _verbose_ with logging level `info`The default configuration should work on all platforms including Windows.
### VSCode
This project already contains some basic boilerplate settings for use with **VSCode**. It contains a `.vscode/launch.json` file and a `.vscode/settings.json` file. The `launch.json` file contains a configuration that allows debugging in VSCode using the F5 key. This will start the NodeRED server with debugging options, attaches the debugger and allows for restarting the debugger when **Nodemon** restarts when it detects source code changes.
### Linters
This project contains a basic configuration for `ESLint` and `JSHint` to enforce some coding and style guidelines. If you use VSCode along with the [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [JSHint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.jshint) extensions you can enforce these during development of your own Node project. Optionally you can also use `Prettier` which can automatically perform some basic formatting when you edit and save your files. VSCode also has a [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) extension.
### Logger
You can enable the custom loggers in the `settings.js` file under key `logging`.
See: [Custom logging module](https://nodered.org/docs/user-guide/runtime/logging#custom-logging-module)
### Files
#### **package.json**
These are the default settings in package.json. For additional information
```js
"config" : {
// The TCP port used by NodeRED (for the editor interface as well as HTTP endpoints)
"httpPort": "1880",
// The address on which the NodeJS Express server should listen on (e.g. localhost, 0.0.0.0, 192.168.1.2, et cetera)
"listeningAddress": "localhost",
// To use HTTPS set 'useHTTPS' to 'true' and provide server certficates in the project root
// The server certificate files (server.crt and server.key) can be generated by running:
// $ yarn create-self-signed --
"useHTTPS": "false",
// Some NodeRED settings:
"nrTitle": "NodeRED Development",
"nrCredentialSecret": "secret",
"nrUserFolder": "./.nodered",
"nrFlowFile": "./.flows.json",
},```
The settings in `package.json` can be overridden on commandline, e.g.
```sh
$ npm run start-debug --node-red-development:httpPort=1234 --node-red-development:useHTTPS=false
```#### **settings.js**
The NodeRED specific configuration is all in `settings.js`.
#### **server.js**
Make changes to server.js if you need to add/change the ExpressJS server such as adding security using Passport.
## Enabling HTTPS
Enabling https is easy following these steps:
1. Change configuration in `package.json` in the config section and set a `useHTTPS` to `true`.
2. run `yarn create-self-signed -- ` which will create new self signed certificates.
3. Start the server by `yarn start` or `yarn start-debug`Note: You can provide own signed certificates by the files `server.key` and `server.crt`. To create your own certificate and private key you can use OpenSSL:
```sh
$ openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt
```## Enabling User authentication
By default everyone has full access to the NodeRED editor. You can limit access by enabling user authentication to the admin interface at `adminAuth` in `settings.js`. You can generate passwords with `yarn create-auth-password -- `. For further information see http://nodered.org/docs/security.html#generating-the-password-hash
_Note: Do not forget to restrict the default permissions in the **adminAuth** section of **settings.js**!_
## Securing http-in endpoints
A great tutorial how to enable JSONWebTokens (JWT) can be found here: [Authenticating Node-RED with JSONWebToken](https://www.compose.com/articles/authenticating-node-red-with-jsonwebtoken/).
## Allow access from other networks than localhost
Change the **listeningAddress** in the config section of `package.json` from **localhost** to **0.0.0.0** to listening on all network interfaces of your host. Alternatively you can also start the NodeRED server with an additional command line option to override the **listeningAddress**:
```sh
$ npm run start-debug --node-red-development:httpPort=1234 --node-red-development:listeningAddress=0.0.0.0
```## Installing NodeRED nodes
NodeRED nodes are installed as **npm** modules. With this project template you have two options when installing new nodes:
1. Project Level
Make sure you are in the main project folder and install using `yarn` as usual. This will save the module as a project dependency in the **package.json** file (or use `npm --save-optional`). For example:
```sh
$ yarn add node-red-contrib-bigtimer --optional
```2. User Level
Change into your user folder (default location is `/.nodered`) before using `yarn`. You might need to run `yarn init -y` the first time if the **package.json** file does not exist in that folder.
```sh
$ cd ./nodered
$ yarn init -y
$ yarn add node-red-contrib-bigtimer --optional
```3. Developing node-red nodes
If you use the setup to isolate the development of a node-red node you should use `yarn link` in your repository folder. Then run `yarn link ` in the **node-red-development** folder to link and install your custom node. Use `yarn start-debug` to start the node-red instance with debugging features. See [npm scripts](#npm-scripts) for more information.
_Note: You can add a Node as a git submodule in a local folder (e.g. `local_modules/`) and `yarn link` from there. This way you have all the benefits of the projects linters as well as debugging your Node under development. Do not forget to run `yarn install` in your cloned submodule to download all it's dependencies. To clone a repository as a submodule:_
> \$ git submodule add -b master [[email protected]:QNimbus/node-red-contrib-openhab-v2.git](https://github.com/QNimbus/node-red-contrib-openhab-v2.git) local_modules/node-red-contrib-openhab-v2
## NPM Scripts
Execute "node server.js"
```bash
$ yarn start
```Start node with active debugging features and `NODE_ENV` set to `development` which will not minify RED.
```bash
$ yarn start-debug
```Generates the hash for the provided password which you can use in **settings.js**.
```bash
$ yarn create-auth-password --
```Generate self-signed certificate and a private key for when running the server in HTTPS mode. You will need to provide the **Common Name** (domain name) _\*_
```bash
$ yarn create-self-signed --
```_\* WARNING:_ The **server.key** and **server.crt** will be overwritten if they already exist.\_
## Security
Because this template has NodeRED embedded into a standard ExpressJS web server you should apply security using ExpressJS features rather than NodeRED. This gives you far more control overall - however if you need to provide read-only access to the NodeRED admin UI you will also need to configure NodeRED security in the **settings.js** file (_nrSettings.adminAuth_). See [Securing Node-RED](http://nodered.org/docs/security.html).
## TL;DR
Follow these steps to install a working development environment in VSCode for a specific NodeRED Node:
**NodeJS**
- Install **[NodeJS](https://nodejs.org/en/download/)** for your platform
- Install **yarn** globally (`npm install yarn --global`)**VSCode**
- Install VSCode extension **[Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)**
- Install VSCode extension **[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)**
- Install VSCode extension **[JSHint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.jshint)****Repository: QNimbus/node-red-development**
- Clone repository into suitable location
`./> $ git clone https://github.com/QNimbus/node-red-development.git`- _Optional_: Start a new development branch
`./> $ git checkout -b dev`- Install dependencies
`./> $ yarn install`- Clone Node repository as submodule, for example
`./> $ git submodule add -b master [email protected]:QNimbus/node-red-contrib-openhab-v2.git local_modules/node-red-contrib-openhab-v2`- Install submodule dependencies
`./local_modules/node-red-contrib-openhab-v2/> $ yarn install`- Link submodule into `node-red-development`
`./local_modules/node-red-contrib-openhab-v2/> $ yarn link`
`./> $ yarn link node-red-contrib-openhab-v2`- Start VSCode and hit F5 to start debugging!
Open a browser and go to the [NodeRED Admin interface](http://localhost:1880/admin) _(http://localhost:1880/admin)_## To do
- Add middleware to secure http-in endpoints (e.g. _nrSettings.httpNodeMiddleware_)
- Add more logging options
- Add optional code to include extended security using Passport