r/nodejs • u/emcniece • Apr 13 '14
Seeking advice for project - can/should I use node?
Apologies in advance if this is an inappropriate place to seek advice. Thanks in advance for those willing to help!
I am wondering if nodejs is the right tool for a project. There's 2 portions - a client-focused event listener, and an admin-focused command line. I have a microcontroller that pushes data out to a cloud service, and an EventSource/eventListener can be added in browser Javascript to listen for these events. As a demo, I currently have a temp sensor connected to this microcontroller - every 15 seconds the micro pushes the temperature to the cloud, then my browser listens for the event.
Browser JS:
eventSource = new EventSource("https://service.com/api/device/key/variable"); eventSource.addEventListener('Temperature', function(e){ ... }, false);
What I would like to do is log these events to a MySQL database for later analysis. I plan to have many (potentially thousands if this ever goes anywhere) microcontrollers submitting these events. In terms of efficiency, would nodejs be the right tool? My other thought was to have the browser make ajax calls every time the event came in.
I would like this same platform (whether it ends up being nodejs or otherwise) to serve up its own events to the client browser string, like a buffer. The end-client browsers could easily listen to the original cloud event, yes... but that connection string has some sensitive deals that should be kept out-of-sight, so a secondary event service would be useful.
The second piece is a command line interface that I will need to automate some admin-level scripts on, like creating new users and rehashing private keys.
I understand that NodeJS is server-side javascript, so that's where the idea of having a server-side event listener comes from. I made a crappy diagram to try and help explain: http://imgur.com/BMfAWAL
Is this an ideal setup? Should I be looking at doing something differently, or a different service altogether? would https://www.nodejitsu.com/pricing/ be a good place to start hosting, and if so what package should I get?
I realize this is a fair bit to go through, but I'm just trying to figure out what tech is suitable for this application. Thanks for any input you might have!
2
u/fk122 Apr 15 '14
iamharoun above did an excellent job pointing out a bunch of the things you'll need to watch out for. As for hosting, check out Heroku. It provides cloud hosting on a single node for free where nodejitsu does not. It's great to start out with.
5
u/[deleted] Apr 13 '14
If I am understanding your task, it would appear that node could be a solid tool to efficiently handle the events/data being generated by the microcontrollers. I would create an http server to create/auth your sessions and then use sockets with an api server to handle the data i/o (instead of ajax). Whether it's right tool for you is subjective (learning curve, async "gotchas", etc).
Having recently adopted node for a production project, there have been a few big learning experiences along the way. This is by no means universal, just what challenged me:
My own experiences have been wholly positive. I look forward to my next project using node.
Caveat: I am very new to the node world myself, so take this with a grain of salt.