1 | NoFlo Node.js runtime environment
|
2 | =================================
|
3 |
|
4 | This tool is designed to be used together with the [Flowhub](http://flowhub.io/) development environment for running [NoFlo](http://noflojs.org/) networks on [Node.js](http://nodejs.org/).
|
5 |
|
6 | ## Prepare a project folder
|
7 |
|
8 | Start by setting up a local NoFlo Node.js project. For example:
|
9 |
|
10 | ```shell
|
11 | $ mkdir my-project
|
12 | $ cd my-project
|
13 | $ npm init
|
14 | $ npm install noflo --save
|
15 | $ npm install noflo-nodejs --save
|
16 | ```
|
17 |
|
18 | Continue by installing whatever [NoFlo component libraries](http://noflojs.org/library/) you need, for example:
|
19 |
|
20 | ```shell
|
21 | $ npm install noflo-core --save
|
22 | ```
|
23 |
|
24 | If you want, this is a great time to push your project to [GitHub](https://github.com/).
|
25 |
|
26 | ## Initializing the runtime configuration
|
27 |
|
28 | The next step is to create the runtime configuration, which will be stored in the `flowhub.json` file in your project folder. Usually you don't want to add this file to version control.
|
29 |
|
30 | You can either create the file by hand, or by the provided `noflo-nodejs-init` tool. See the included help information:
|
31 |
|
32 | ```shell
|
33 | $ node node_modules/.bin/noflo-nodejs-init --help
|
34 | ```
|
35 |
|
36 | You can also run node node_modules/.bin/noflo-nodejs and provide most of the parameters on the commandline to run without flowhub registration.
|
37 |
|
38 | ### Host address autodetection
|
39 |
|
40 | There are situations where the IP address of the runtime will change. For example, when you're running a NoFlo runtime on a [Raspberry Pi](http://www.raspberrypi.org/) that you carry between home and the office. This runtime tool has rudimentary support for IP address autodetection.
|
41 |
|
42 | To enable that, run:
|
43 |
|
44 | ```shell
|
45 | $ node node_modules/.bin/noflo-nodejs-init --host autodetect
|
46 | ```
|
47 |
|
48 | After this the runtime will report its current IP address to your Flowhub UI whenever it is started.
|
49 | Autodetection will prefer external interfaces over local one (e.g. the loopback interface).
|
50 | If you prefer a certain network interface you can use "autodetect(<iface>)" e.g.
|
51 | "autodetect(wlan0)" to check that interface if it is online. Again you can also use the
|
52 | --host option on node_modules/.bin/noflo-nodejs for unregistered usage.
|
53 |
|
54 | ### Example flowhub.json
|
55 |
|
56 | `$ node node_modules/.bin/noflo-nodejs-init` will initialize `flowhub.json` with the `id` of the runtime. The `user` id comes from Flowhub > Home > Runtimes > Register. You'll need some more info to make the registration useful:
|
57 | ```json
|
58 | {
|
59 | "id": "runtime-id-...",
|
60 | "user": "user-id-...",
|
61 | "host": "autodetect",
|
62 | "port": 3569,
|
63 | "label": "my-runtime"
|
64 | }
|
65 | ```
|
66 |
|
67 | To generate this file, you could run:
|
68 |
|
69 | ```shell
|
70 | $ node node_modules/.bin/noflo-nodejs-init --host autodetect --port 3569 --user user-id --label "my-runtime"
|
71 | ```
|
72 |
|
73 | In this case the UUID for the runtime (shown as `runtime-id` in the JSON above) would be autogenerated. If you want to reuse a previous one, you can provide it with the `--id some-UUID` option.
|
74 |
|
75 | ## Starting the runtime
|
76 |
|
77 | Once you have configured the runtime, it is time to start it:
|
78 |
|
79 | ```shell
|
80 | $ node node_modules/.bin/noflo-nodejs
|
81 | ```
|
82 |
|
83 | This will start a WebSocket-based NoFlo Runtime server, and register it to your Flowhub account. It should now become available in your Flowhub UI. By default the configuration will be read from the current working directory, but you can change this by setting the `PROJECT_HOME` environment variable.
|