About node. js
First, node. JS is not a language, it's a platform. Because JavaScript was used primarily for Web page interaction, it had to be attached to the browser and only on the browser would it be possible to run JavaScript. Later, more and more users of JavaScript, ECMAScript standard is gradually improved, more and more functions, some people want to use JavaScript to write back-end eminence to do a full-service engineer, so the emergence of node. js. node. JS is integrated with the Google V8 engine to execute code, and most of the modules are written in JavaScript. This allows JavaScript to work separately from the browser's environment, so there is more JavaScript usage scenarios.
Event-driven
node. JS is event-driven, so it can handle high concurrent requests. and node. JS is non-blocking. About this non-blocking in fact, I have not quite understood, but now I seem to know a little. Because node. JS is written based on JavaScript, JavaScript has an important feature of asynchronous programming.
(JavaScript is replaced with JS)
Because JS itself is a single-threaded, that is, a JS file, executed in accordance with the order of the sentence execution. So how can it be asynchronous? This problem has been bothering me for a long time. In fact, Async does not refer to the asynchronous JS itself. Because JS is running in the browser, the browser is a number of threads, in the execution of the asynchronous request statement to JS, the following statement needs to wait until the request is completed before execution, which will block the subsequent statements, this time the browser is suspended animation. So the asynchronous request is to ask the browser to open another B thread, b thread is different from the current execution of the thread of JS, and then through the callback function to return the request results, this time, the asynchronous request to the B-thread to do, this JS file left the statement can continue to execute. Until the b thread is done, and then the callback function to return the results to JS to handle, this time, such as JS handle busy things are busy, you can return the results one by one to deal with. (It seems a bit messy, the next change)
node. JS is non-blocking and is mostly implemented with asynchronous requests (personal understanding, please note).
Eventemitter
Because node. JS is event-driven, the events module is very important. Class Eventemitter is the definition and implementation of the events module.
Today is mainly to learn some of the methods of Eventemitter, but node. JS API A lot of things can not understand, should be es6 new features, such as the definition with the const, there are functions do not write function (A, B) {//.} But written (A, b) =>{//...} Such a pattern, a little less accustomed.
Let's write it down here today.
node. JS Learning-1