Once I got started slinging some code I did come to the conclusion that I was right about the good things and was overly worried about the bad. This said, the async nature of the Node.js model does give me headaches. Below is a narrative that presents some of the key processing flow for the app that I am developing:
“The App” modules “main” and “form” integrate with the Node.js to provide a web server as described by the example on this page. This is somewhat different than most development environments where handling of the web interface is more abstracted from the application code!
- “The App” is launched at startup with main running and a “/” is fired from the browser running on the LCD display as console.
- “main” is monitoring the http port and sees the “/”. It invokes form.send to put the main.html form out to the client.
- When the user presses the “Start” button main sees it and invokes form.receive to handle the page. The call to form.receive is made with a callback given that receiving a form is asynchronous.
- form.receive does inspects the return from the client to see if the button pressed on the received page is asking for a new page (versus some other action).
- In this case the button press indicates that we need to start a test so the appropriate html file is sent to the client using form.send and the callback is completed after populating global.context with the name of the page sent and with the button pressed on the client.
- Main then receives that callback, sees that we want to start a test, loads the test module, and calls test.execute.
- test.execute starts running and does a setInterval to begin collecting our observations.
- setInterval fires as often as it can calling test.observe to do our data collection.
What I have built seems to work well but I am sure that I could have done it better!