How Does it Work?
So, how does JS do everything it does? Where is it the best? To understand how it works, when and where, first, we need to speak of its nature.
JS is a single threaded and single concurrent programming language which means it can handle one task at a time or, in other words, a piece of code at a time. It’s an interpreted programming language, and like most scripting languages, it uses dynamic typing, where type safety is verified at the runtime. But how JS runtime handles tasks or executes asynchronous codes?
Asynchronous programming is great for a faster execution of programs but it is difficult to develop and most of the time you might end up with callback hell situations. So to avoid it you can modularise your code, use generators, promises, event-driven programming or Async.js.
JS is considered a lightweight programming language and one of the many reasons is that it does not have any variable types, unlike other languages. It has very small memory footprint and is easily implemented. This is important especially for porting.
JS becomes more lightweight as more and more libraries and frameworks are released. Vue, Ember, Angular, Riot, Polymer are some of the top JS lightweight libraries.
This interactive language has also a great support for learning, great debugging tools available and much more. It gives an opportunity for a really fast development, which obviously increases productivity. It also has high-scalability, meaning that you don’t spend much on infrastructure as you need less hardware to handle the same amount of load.
So, what to do with JS and what not? So here is the short list of where JS is the best and where it yields, learnt from our own experience.
WHAT YOU CAN DO WITH JS
#write web applications for browsers
#create browser extensions
#make desktop apps
#run it on microcontrollers
#create native mobile apps
WHAT YOU SHOULD RATHER NOT DO WITH JS
#command line tools
We know you can develop command line tools using Node.js, and that will be okay. But what if you need to develop not small, rather than big command line tools like git, docker, etc. You'll need multi-threading and fast computations. We tried to build our history-transactions tool which will run in command line, we used Node but when the app grew, we noticed a lot of performance issues in various computers and VMs, even if there wasn't out of memory exception, the program worked very slowly. So we ported our program to Go which provides excellent multi-threading system with its own co-routines mechanism.
SHIFTING TO JS FROM OTHER LANGUAGES
In some cases, there’s a need to change code base to another language or re-write server-side code to improve performance.
JAVA TO JS
RUBY ON RAILS TO JS
PHP TO JS
If you are a PHP developer and want to change your domain then it is good to go with Node.js. Node.js has low learning curve to get started and has over 250,000 packages on NPM available to assist you during development. It is asynchronous and has non-blocking I/O loop by default, in addition to this it has a very large community supporting it. Whereas, if you want to port your PHP code to Node.js due to scalability issues then here, too, Node.js is a very good option. It can easily handle 10k simultaneous connections due to its asynchronous nature.
Every language has its pros and cons. So if you want to rewrite your entire server-side code, think first. Probably you can break your server to microservices and use what language you want instead of rewriting all codebase from scratch. Think Slow, Do fast!