This document provides an overview of Node.js, including its history as a project started in 2009 by Ryan Dahl, why JavaScript was chosen as the programming language, how its single-threaded and asynchronous event loop model works well for I/O-intensive jobs but can struggle with CPU-intensive tasks, and some gotchas to watch out for like using synchronous APIs, loops, recursion or causing excessive garbage collection which could freeze the process. The document aims to explain what Node.js is and some of its key characteristics and limitations for different use cases.
This presentation is to help you be critical in choosing Node.js as tech solution, not to boost Node.js
Node.js can be anywhere, except space shuttle.
io.js a fork of original node.js, because some people is not satisfied by slow steps of node evolution.
When these two merge, node.js is still 0.xxx, but io.js has reached v3.3.1. So, the new version of node.js starts with v4.
This story sounds similar. Yes, same happens for HTML5.
LTS(v4, v6) vs Current(v5)
LTS focus on stability and security.
Current focus on new features.
Node has only very basic and raw functionality
It is NPM that makes it powerful.
JavaScript is asynchronous, by default.
JavaScript had no existing IO libraries so we could start clean with non-blocking IO.
Example. Crawler in .NET
Actually, Universal JavaScript is the biggest incentive.
Frontend Engineers are most loyal language user, since they have not much choice.
It is difficult, but not impossible.
Node.js helps scale-up, not scale-out.
Actually, it doesn’t implement share-nothing-architecture like PHP. As a result, it may suffer some scalability problems.
http://softwareengineeringdaily.com/2015/08/02/how-does-node-js-work-asynchronously-without-multithreading/
It is a hoax that Node process has only single thread.
There are multiple threads, but your code always run on single thread.
Check it out:
ps –M {pid}
Single Threaded brings pros:
No race condition;
Better performance since thread switching is not necessary.
In Node.js everything runs in parallel, except your code.
What this means is that all I/O code that you write in Node.js is non-blocking, while (conversely) all non-I/O code that you write in Node.js is blocking.
Dougalus Crockford’s response: never!!!
JavaScript is application language, not system language.
https://www.youtube.com/watch?v=QgwSUtYSUqA
https://blog.jcoglan.com/2013/03/30/callbacks-are-imperative-promises-are-functional-nodes-biggest-missed-opportunity/
Ryan Dahl decides to take CPS way.
Example. Read cson config in view
So, every server application should have two phase:
Init phase;
Execution Phase.
Example:
Read cson from loop in view.
Example:
_.merge
Example:
Plurk
Node.js GC is actually google v8 js engine GC.
So, it runs in single thread.
Example, plurk moves away from node.js