Gameplay Journal Entry 1

Destiny 2 has a strange phenomenon occurring within it. Recently, the developers introduced a new drastic system change called “sunsetting.” The player base knew about this system change for a while…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Why Node.js is a good choice for your next web app

You might have noticed the big surge in Node.js’ popularity in the recent year or two. Why is that so?

Why is it getting so popular despite well-tried languages like PHP or Python? Why you might want to consider using it for your next project? Or why you might want to avoid it in your particular case? Let’s go through some of the points, but first…

Technically speaking, Node.js is a runtime environment for JavaScript that can be used on servers. It runs your code on a single-threaded event loop that is asynchronous in nature and doesn’t block the input/output. To put it simply, it’s JavaScript on the back-end and it is darn good.

But why?

If there is something awesome about software developers, it’s that we are a bunch of lazy fellows, but lazy of a good kind. We invent better tools that provide us with more time to research, to invent completely new needs, and to help us fulfill them. Node.js is a great tool to choose and a pleasant one to use as well. There are a lot of reasons why developers (and business folks!) like it, and here are just some of them.

Node.js is a demon of speed when it comes to handling requests and input/output operations such as database or hard drive access. This characteristic makes it a perfect candidate for APIs that potentially need to handle hundreds of thousands of requests from your users. In the heart of Node.js stands V8 engine; it’s the same piece of code that runs JavaScript in the Google Chrome browser. V8’s automatic code optimisations allow it to compete with languages like Go or Java despite being a scripted language, not a compiled one! This gives us developers the best of the both worlds: ease of work of a scripted language and performance comparable to a compiled one.

The reason why Node.js can perform so well is (apart from V8’s magic) its asynchronous nature. It won’t block the input/output calls, meaning that it can handle many things at the same time instead of waiting for them to finish in order. Of course, other languages also have their ways of dealing with it but in Node.js, asynchronicity is a first-class citizen. Thanks to that, Node.js developers have less headache from usual problems of concurrency and parallel processing like deadlocks and race conditions.

Using real-time communication methods like WebSockets is a breeze with Node.js due to the first-class asynchronicity. Notification systems, chats, and real-time feedback in your apps like the “is writing” prompts, search-as-you-type, and many others are easy to implement.

But what if speed and async is not enough? What if your hardware is overburdened? Buying bigger and faster servers to match the increasing needs of your users is not feasible — it costs a lot of money. Horizontal scaling (across multiple cheaper machines) is very easy in Node.js-land. Basically, this means spinning many Node.js processes at the same time and putting a load balancer (like nginx) in front of them. They will share the burden between themselves.

There are many good materials about scaling floating online, but Node.js’ own documentation for cluster module or things like Docker Compose (with nginx as load balancer) are usually used. You can even apply solutions like Docker Swarm or Kubernetes for smart auto-scaling features.

JavaScript grew to a modern and beautiful language. It’s rapidly changing and adapting to the community needs. Currently, it is a pleasure to use, and it’s really easy to start learning to code back-end applications if you already have some prior JavaScript knowledge. Additionally, the most popular Node.js frameworks like Express.js, Koa or Hapi are pretty straightforward. The times of dreaded callback hells are also gone thanks to Promises and async/await models that significantly lowered the learning curve.

You might be thinking that from this day forward, everything that you ever make should be written in Node.js. Unfortunately, Node.js is just a tool, and it isn’t a great fit for everything and everyone.

Node.js should be avoided in two cases: CPU-intensive applications and applications that don’t require custom software development.

We’ll start with the latter. It’s a general question for every single language and framework out there: if you need software to manage stock in your warehouses, do you really have to code it from scratch?

OK, what about that CPU part? The way Node.js works and the way it’s built should have some drawbacks. It’s just not as fast as some other languages in pure CPU intensive tasks: things like blockchain, heavy machine learning, photo/video manipulation, etc.

So what kind of apps is Node.js a fit for? Due to its fast I/O and non-blocking asynchronous nature, it’s great for developing streaming or event-based real-time applications that don’t require that much of CPU usage. For example:

Therefore, should you use Node.js for your next app? Yeah, probably (with a bit of a research). There are many reasons why big enterprises are starting to adopt Node.js although they don’t like changing their technology stacks by nature.

Add a comment

Related posts:

Best smart sprinkler controller

Watering the lawn and garden is a thankless chore, and it tends to be especially wasteful if done with a hose in one hand and a beer in the other. Irrigation systems have made home watering simpler…

I Compliment 6 Strangers Every Day.

Why strangers? Because I see people who need it. I live in New York City, where lots of people could use a bright spot in their day, especially during their commute. Today while on my way to my…

Dependency injection in Jenetics

When I was implementing the Genetic Algorithm (GA) and Genetic Programming (GP) library, Jenetics, it was clear that I needed a way to change the PRNG implementation the GA was using during the…