Connecting node.js server (w/ mongodb database) to openframeworks drawing application


Basically I would like to transfer data from my web application created through node.js where I have data stored in collections in mongodb, and I want to use this data as an influence to my drawing application in openframeworks. What is the best way possible to communicate this data between these applications? Thanks.

hey hey,
there are many ways to do that. which protocol to choose depends on your requirements. here are a few that came to my mind.

  • OSC
    it is very common for time-critical applications, some packages might get lost, as it is UPD based. package size is limited (depends on your network, router, switches, …, OS). Check out the ofxOsc examples. It is relatively easy to implement it on the oF side. the nodejs counter part could be handled by the node-osc package.
  • websocket
    not as fast, but in most cases fast enough. it is TCP based, hence no loss of packages. your node app could open a websocket server and the oF app could connect to it, there are oF addons for using websocket clients, not sure whats the most recent one.
  • mqtt
    instead of websocket you could also use mqtt, especially if you work on more complex systems with more clients, communicating via different channels. downside here: it requires a broker which handles connections.

hope that helps

1 Like

+1 for OSC
I’ve connected node.js (well meteor.js) to oF using ofxOsc and node-osc and it’s very responsive.
The thing I like about using OSC is that it’s a commonly used protocol so it’s easy to debug issues using other apps. I especially like Protokol to aid debugging.

and MQTT would work well if the latency is acceptable.

my recommend:

  • OSC (for small and simple structure data)
  • zmq with json (or bson, etc…) (for complex structure data)

Hey thanks for the suggestion! Looking into ofxOsc and not sure how to get the mongodb data into the oF app and use it. Since you’ve already connected the apps I want to know how exactly or if there are any tutorials to achieve the connection. Please and thank u

How can I access the specific data from the database in the oF app (to use as values that will affect the drawing)?

I had a Meteor.js app running on DigitalOcean. Then I had a Chrome browser open on a specific page used only for queuing data for OSC sending. Meteor bundles node.js and mongodb (plus a few other things) that make it easy to build real time web apps. My queuing page monitored for mongodb updates and sent OSC messages to the oF app over the local network using node-osc.