Evolution of a Blog

This blog has evolved as I have as a maker. It starts at the beginning of my journey where I began to re-tread my tires in the useful lore of micro electronics and the open-source software that can drive them. While building solutions around micro-electronics are still an occasional topic my more recent focus has been on the 3D Printing side of making.

Wednesday, October 9, 2013

Node.Js Web Page Processing (Using 'html' Library)

Node.Js supports a number of libraries to facilitate handling of web interactions.   One of the most primitive is 'html' with 'connect' and 'express' further up the food chain.   When I started my project I looked for examples of express being used for a reasonably traditional web application and did not find one.   What I found was one that gave me a foundation for putting together an application based on the somewhat primitive functions provided by 'html'.

I am actually ok with that as it has given me a lot of control.   I have implented the
“The App” with two modules “main” and “form” that integrate with the Node.js to provide a web server as described by the example on this page. 

  1. "The App” is launched at startup with main running and a “/” is fired on behalf of the LCD display.
  2. “main”  is monitoring the http port and sees the “/”. It invokes form.send to put the main.html form out to the client.
  3. 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 reveiving a form is asynchronous.
  4. 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).
  5. 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.
  6. Main then receives that callback, sees that we want to start a test, loads the test module, and calls test.execute.
  7. test.execute starts running and does a setInterval to begin collecting our observations.
  8. setInterval fires as often as it can calling test.observe to do our data collection
What is not shown on this page is the library backbone.js.  This library consolidates related processing from main and form into one place for readability.   The async processing shown here still applies.

Sample code for this demo can be found on GitHub.

No comments:

Post a Comment