Reasons to use JavaScript / Node
I'm currently working on some slides for JavaScript / Node.js training I will be running for our company. Since there is plenty of material on the internet to bash JavaScript I thought I would share a few of the opening slides which try to explain why I love JavaScript. :)
Why Use
Server and client side in the same language
For a solo developer, using the same language on both client and the server side removes a big chunk of cognitive load.
In a team, application developers can be used to work on client as well as server side code. It is also easier for the team to understand both halves of the code which will have a positive effect on the interaction between the two halves. There will be more competent pairs of eyes for code reviews.
The same tools can be used for building and testing both halves of the application code.
Incidentally (and somewhat as an aside) I am also against using transpilers (e.g. Babel, /(?<!Java)Script/ flavours of the language, etc.). Anything that makes the code different from the source when you look at it in the debugger is something that increases cognitive load and reduces efficiency. Just write clean, well structured code with well documented API, backed by good unit / functional tests and you will be a legend among your peers! :)
Simple enough for you to feel free
JavaScript is a very simple language especially if (and you should) stick to "The Good Parts". The people behind ES6+ have tried hard to add complexity but it is still possible, given a good programmer, to write clean, simple and well structured JavaScript code.
Enough hammers not to forge your own every time
You get all the usual built-in methods. Not as many as some other scripting languages, but enough to be useful out of the box.
You get basic data structures with the built in methods to use them in the ways they are usually used.
Node.js provides lots of very useful modules to build fully-featured network applications.
Fast enough
While client-side performance varies browser to browser, the V8 engine behind Node.js is really fast. Like 1/4 of the performance of real-life network applications written in C (hint: asynchronous programming, clustering support and network latency in general all take a surprisingly large chunk out of what should be a much wider performance gap).
Good enough to structure larger programs
It is entirely possible to write large and complicated applications in JavaScript given enough discipline and skill. Admittedly, it is easier to do in Node.js than in the browser, but it is still possible to do both.
Browser is the only cross-platform GUI toolkit
This might not be exactly true since QT is quite proficient at running on multiple platforms but it is true enough in general.
When to Use
Web applications
This should neither come as a surprise, nor require further elaboration. :)
Network clients and servers
Node.js makes for a surprisingly good choice when writing network applications. It has much better performance than most other scripting languages and (once network latency has a say) it can perform very reasonably compared to "proper" programming languages in a fraction of the development time.
When not to Use
Computation (CPU) heavy programs
Being a scripted language JavaScript is still really slow when it comes to CPU-intensive tasks.
The solution on the client-side is to stop writing lots of complicated JavaScript code for the poor browser to run (and your poor users to endure)!
On the server-side, it is possible to offload such tasks to native code either via FFI, or (if you are really brave) by writing custom C/C++ addons for Node/V8/libuv.
Very high loads
Node's asynchronous nature is great but it only takes you so far. Once you are in the territory of several thousand requests a second you will need to either scale (using clustering and / or multi-server architecture) or use a faster language.
Node applications also consume vastly more memory than their compiled equivalents.
Shell scripting
Asynchronous and shell scripts just don't mix well together in my experience. Use a more suitable tool for the job – there are plenty to choose from.
Raw socket requirement
If you need to mess with the packets you are sending out then you're out of luck (unless you write an addon to hook into libuv under the hood).