Working in Node.JS


Working in Node.JS

Lately I’ve been working in Node.JS building an API for our application. We are slowly breaking free from our Rails 4 application and switching our architecture to a client server architecture. I know Rails is fully capable of providing a JSON REST api but the existing application is in such poor shape that it would take years to re-write the application. I don’t think this was the developers fault but more of the lack of experience combined with a lousy architect.

Why pick Node?

Node.js has seen a very large adoption, there are libraries that can communicate with our multiple database and mult-tenant architecture. It’s important when picking a new language that you make sure it’s stable, fast and can be used across your existing architecture. Node has all of those and the lanaguage JavaScript has seen improvements with ES6 that I feel makes the lanagugage even more powerful. The other major factore was that we all knew JavaScript already. Which was one of the reason why we didn’t choose Go or a different language.

The frameworks that we are using are Express.JS to handle the REST API. Express has been great to work with. One of the key advantages in using express is taking advantage of how it uses middleware. This lets us write our sevices at a more module level. The best advantage is since writing our API as modules, if we notice that our load is changing and we are getting lots of traffic, we can split that module out of the API. Create a new service with the same code and deploy that to as many servers as we need. This is kind of how we handle micro-services. We can easily scale only portions of our application without needing to scale the entire application like what we would have to do with our Rails Application.

The community is amazing around Node.JS and JavaScript. This was one of the reasons why I switched to Ruby from .NET. It had more people that weren’t snoody. I think you all know who those people are, the people that bash you for using language X or lanaguage Y. The ones that make you feel stupid and like you don’t belong. The JS community has been very giving, understanding and it’s amazing talking to some of these people on IRC, Twitter, Slack and seeing how open they are to having conversations and to help you out if you have questions. That is something I want to be apart of and I know others do as well.

Next Step

The next step for us is going to be extending out our API to other platforms. We have grand dreams of building that app that goes on your watch, what would it look like if we built notifications and put them on your refrigerator? Maybe we will continue to use JS to build an Electron Desktop application, a JS version for the Pebble smart watch.

Having an architecture that gives us that freedom is what is going to let us become successful. We take something very complex and make it accessible for everyone to use.

Conclusion

I’m going to be focusing on showing how to build API’s using Node.JS with different technologies. This is meant for more backend developers. I’ve started taking a liking to this area and I think I’m going to run with it. I’ll try and focus on some basic applications in the future.