# red-bed

> Embedded node-red with convention based layout and dependency injection

Latest version **4.2.0** (published 2020-01-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install red-bed
pnpm add red-bed
yarn add red-bed
bun add red-bed
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.2.0 |
| Published | 2020-01-28 |
| First published | 2019-08-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 259.2 KB |
| Known vulnerabilities | 0 (+3 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | smc-tenacious |
| Keywords | node-red |

## Links

- npm: https://www.npmjs.com/package/red-bed
- Repository: https://gitlab.com/tenacious/red-bed
- Homepage: https://gitlab.com/tenacious/red-bed#readme
- Issues: https://gitlab.com/tenacious/red-bed/issues
- npm.io page: https://npm.io/package/red-bed

## Dependencies (19)

- [ajv](https://npm.io/package/ajv.md) ^6.10.0
- [nedb](https://npm.io/package/nedb.md) ^1.8.0
- [sift](https://npm.io/package/sift.md) ^9.0.4
- [plebs](https://npm.io/package/plebs.md) ^1.2.0
- [bcrypt](https://npm.io/package/bcrypt.md) ^3.0.6
- [lodash](https://npm.io/package/lodash.md) ^4.17.14
- [express](https://npm.io/package/express.md) ^4.16.4
- [mustache](https://npm.io/package/mustache.md) ^3.1.0
- [node-red](https://npm.io/package/node-red.md) ^1.0.3
- [node-rsa](https://npm.io/package/node-rsa.md) ^1.0.5
- [traverse](https://npm.io/package/traverse.md) ^0.6.6
- [camelcase](https://npm.io/package/camelcase.md) ^5.3.1
- [commander](https://npm.io/package/commander.md) ^2.20.0
- [underscore](https://npm.io/package/underscore.md) ^1.9.1
- [await-delay](https://npm.io/package/await-delay.md) ^1.0.0
- [convenient-di](https://npm.io/package/convenient-di.md) ^2.1.0
- [happn-sillyname](https://npm.io/package/happn-sillyname.md) ^0.1.1
- [node-red-dashboard](https://npm.io/package/node-red-dashboard.md) ^2.19.3
- [node-red-node-email](https://npm.io/package/node-red-node-email.md) ^1.7.3

## Recent versions

- 4.2.0 (latest) — 2020-01-28
- 4.1.0 — 2020-01-22
- 4.0.0 — 2020-01-09
- 3.0.0 — 2019-12-02
- 2.1.0 — 2019-10-24
- 2.0.2 — 2019-10-23
- 2.0.1 — 2019-10-22
- 2.0.0 — 2019-10-21
- 1.1.0 — 2019-10-18
- 1.0.2 — 2019-08-30
- 1.0.1 — 2019-08-19
- 1.0.0 — 2019-08-19

## README

[![pipeline status](https://gitlab.com/tenacious/red-bed/badges/master/pipeline.svg)](https://gitlab.com/tenacious/red-bed/commits/master) [![coverage report](https://gitlab.com/tenacious/red-bed/badges/master/coverage.svg)](https://gitlab.com/tenacious/red-bed/commits/master)

red-bed:
-------
*Embedded node-red with convention based layout and dependency injection*

premise:
--------
This module makes it really easy to create an embedded node-red project, it also consumes a convention-based folder structure that allows for the creation of a set of base services - with dependency injection baked in via the [node-dependency-injection](https://www.npmjs.com/package/node-dependency-injection) module.

The custom nodes for your embedded project are also created within the folder structure and are automatically built into the solution, they can access the base services. The idea here is that the nodes and node-red do flow control and expose endpoints and the services do the heavy lifting.

More about the folder structure:
--------------------------------
```
--project root
      |____node-red  --> the folder flows and node-red config lives in
      |____nodes     --> where custom nodes are set up
      |____public    --> static content
      |____schema    --> json schemas, for schema validation of node-red messages, not implemented yet
      |____services
      |       |____service name
      |                |____service name-service.js
      |____config.js --> the configuration file for the project, look here for [the example config](https://gitlab.com/tenacious/red-bed/tree/master/test/__fixtures/example-project/config.js)
```
dependency injection and services in more detail:
------------------------------------------------
NB: service class files must be named according to the convention: (project root)/services/(service name)/(service name)-service.js
*all services inherit from the red-bed Service class*
```javascript
const Service = require('red-bed').Service;

class Example1Service extends Service {
  //config -> the service config, actually the whole config for red-bed, so not just limited to config.services.example1
  //common -> injected common utilities and logging
  //example2 -> the injected example2 service, which is found by performing reflection on the constructor
  constructor(config, common, example2){
    super(config, common);
    this.example2Service = example2;
  }

  async init(){ //for initializing dependencies

  }

  async start(){ //the startup method

  }

  async stop(){ //the stop and teardown method

  }

  defaults(){ //setting up defaults
    this.config.customSetting = true;
  }
```

getting started with the example red-bed service:
------------------------------------------------

1. Clone, install and run, -p = project folder, -w = admin password:
```bash
git clone https://gitlab.com/tenacious/red-bed.git && cd red-bed && npm i && node bin/init -p test/__fixtures/example-project -w test
```
2. Login and view node-red setup:
you can login to node-red on http://localhost:8000/admin (username admin, password test) and modify/view the test flow

getting started with your own red-bed service:
----------------------------------------------

1. Install
----------
```bash
npm i red-bed
```

2. Folder structure and config file
-----------------------------------
copy the contents [test example folder structure](https://gitlab.com/tenacious/red-bed/tree/master/test/__fixtures/example-project) to your project folder path, or lib folder.

3. Create a runner js file
--------------------------
```javascript
let server = require('red-bed').Server.create({
  projectPath: path.resolve(__dirname, './my/project/folder')
});
await server.start();
//await server.stop(); //for later
```

4. Run runner.js
-----------------
```bash
node runner.js
```

5. You can view the test flows now, go to http://localhost:8000/admin, login with username admin, password can be anything for now.
--------------------------------------------------------------------------------------------------

---
_Source: https://npm.io/package/red-bed · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
