npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

red-bed

v4.2.0

Published

Embedded node-red with convention based layout and dependency injection

Downloads

26

Readme

pipeline status coverage report

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 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

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:
git clone https://gitlab.com/tenacious/red-bed.git && cd red-bed && npm i && node bin/init -p test/__fixtures/example-project -w test
  1. 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

npm i red-bed
  1. Folder structure and config file

copy the contents test example folder structure to your project folder path, or lib folder.

  1. Create a runner js file

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

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