Node.js - Express - Elastic Beanstalk - Mongodb.js

I have started using Node.js with Express framework in a company that wants to move Oracle’s PLSQL procedures that render html and have the process done in Node.js, so ORACLE will be using for only storing data.

After that good experience I migrated a website built in Wordpress to NodeJs so I can have my own code because I want to do more cool stuff and improve the user experience and the quality of the website.

Node JS + Express

Express is the framework to build a web server or API easily. It’s really easy to start and have,quickly, our first “hello world”.

The only thing that can be a problem is that you need to handle the errors and exceptions because those can bring the Express server down. You must handle errors properly and if an error not catched makes the server go down, the code has to be prepared to start a new web server automatically. To accomplish that, you have to build the server inside a cluster.

The use of cluster also makes it possible that the server can use all CPU core that are available in your infrastructure. Check this article for more information.(https://expressjs.com/en/advanced/best-practice-performance.html#handle-exceptions-properly)

MongoDB

I’m very happy with Mongodb. It’s simple to use and the documentation is complete. The biggest benefits for me are that you can save and retrieve JSON objects, I can easily integrate Geo Location based queries (a cool feature) and I can easily change the DB structure.

What? Yes, I know MongoDB is a structureless database but I have used Mongoose (in my API Node.JS), so the DB structure is there. That’s great because you define all your models in only one place: the API. Those models can be used by Mongoose and also to be used in other parts of your API NodeJS’s code.

In addition I have a “composite” model definition: I reuse some inner model definitions in several parent models. For example a “Place” model shares the GEO position model and that inner model is also a child model of “Business” model.

About robustness: I have been running a website for 4 years and that DB never went down or had a slow response in these years.

AWS Elastic Beanstalk

This is a server technology. It’s part of one of Amazon Web Services. It allows you to have multiple environments and deploy your code from the command line. One cool feature is that when you deploy it, it launches a new server instance so your site never goes offline. If it fails nothing will happen. You still have your “old” instance running.

The main benefit of using AWS Elastic Beanstalk is that it can launch multiple instances automatically if your server is under high pressure (a lot of traffic or long processing going on). It can be configured to start new instances based on memory usage or cpu usage. You have a settings page where you can configure that load balancer.

I found it a little difficult to know which threshold to set and what value. So at the end it was a matter of setting a parameter that I felt good with and then see how the server responded.

Conclusion

I think this stack is great for a lot of applications, it’s robust, safe, quick and easy to manage.

I really like to develop using the same language in frontend and backend. MongoDB is also great when you don’t need complex queries (like a lot of joints).

About Elastic Beanstalk the only key point is to not trust in it’s internal memory (RAM) (because your instance can be ended when you deploy or you can even have multiple instances running, when you have set up a load balancer with autoscaling).

I have integrated it with a payment gateway and it worked really ok.


Profile picture


Hi, I'm Leandro Merli and this is my blog where I write about Angular, AWS, Node.JS, Serverless, Wordpress and now I'm testing and using Gatsby as SSG (static site generator), the framework I used to build this blog. :) Please follow me on medium.com or contact me in linkedin