2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Node-REDでHello World!

Last updated at Posted at 2021-06-26

Node-REDとは

Node-REDはフローベースドプログラミング(flow-based programming)ツールであり、元はIBM Emerging Technology Servicesチームによって開発され、JS Foundation配下のプロジェクトを経て、2019年3月よりNode.js FoundationとJS Foundationが合併して設立されたOpenJS Foundationにホストされています。

Node-RED User Group Japan - 概要

  • ブラウザ上のエディタを使って、ノーコード、ローコードで開発できるOSSです。
  • デザイナ上で、[ノード]を作成・処理を記載、[ノード]間を接続し、データを受け渡して処理を行うフローベースのプログラミングです。
  • Node.js上で動作しています。IoT機器、PC端末などのエッジデバイス、フロントエンド、バックエンドまで動作させる事が出来ます。

実行環境

  • WSL上のUbuntu 18.04 LTS
  • Dockerインストール済み

Dockerで起動。

  • 以下コマンドを実行
    • /home/user1/dev/node-redでコマンドを実行
    • /home/user1/dev/node-red/.node-red を永続化しています。
docker run -it -p 1880:1880 -v /home/user1/dev/node-red/.node-red:/data --name mynodered nodered/node-red
  • 正常に実行されると以下のメッセージが表示されます。
26 Jun 07:47:08 - [info] Server now running at http://127.0.0.1:1880/
26 Jun 07:47:08 - [info] Starting flows
26 Jun 07:47:08 - [info] Started flows

image.png

  • ブラウザで http://localhost:1880/ にアクセスします。
  • エディタに無事アクセス出来ました。

image.png

チュートリアルを実施

image.png

  • デプロイボタンをクリックし、デプロイします。

image.png

  • デバッグタブを選択

image.png

  • プログラムを実行したいと思います。
  • [Inject]ノードのボタンをクリックしましょう。タイムスタンプがメッセージ出力されるはずです。

image.png

  • 想定通り、タイムスタンプが出力されました。

Hello Worldを作成

  • 少し、改良して"Hello World"の文言を出力してみます。

  • [Injection]ノードを削除、[Function]ノードを追加します。

image.png

  • [Function]ノードをダブルクリックし、[コード]に以下入力します。
msg.payload = "Hello! World";
return msg;

image.png

  • [完了]ボタンをクリックします。

  • [Injection]ノードを追加し、以下編集します。

image.png

  • 再び、[Injection]ノードと[Function]ノードと[Debug]ノードをワイヤーでつなぎます。

image.png

  • 先ほどの手順と同様に[デプロイ]ボタンをクリックします。

  • [Injection]ノードをボタンをクリックし、プログラムを実行します。

image.png

  • 以下、無事に"Hello World"が出力されました。

image.png

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?