Pre-language: Nodejs This book has been bought in May, then just contact node, Ben thought this book should be node entry-level more systematic book, can turn over a few pages, found a lot of places are obscure, especially to see the built-in module of C + + implementation, an instant to feel sleepy ....-_-from this, the book has been my idle in the corner of the desk, no move, read the idea of learning node so give up, into the Internet Learning Basic Grammar API. In this way, look at the API side to do some small examples, slowly, found that the basic API usage has mastered, so, to search for some technology blog related to node, hope to be able to advanced to understand node. Start to try to do some complete small examples with node, such as simple blog implementation, chat room ... So after two months or so, found that the understanding of node basically has a comprehensive understanding of the general, all the knowledge points are almost familiar with, so began to implement a simple ordering app, before, in order to be able to strengthen all the knowledge points to successfully complete the server-side writing, Once again opened that a little bit of dust << nodejs>>, this time, without the first of the kind of strange shyness, some only to the existing knowledge system expansion and strengthening, then, I will use their own language to write down the important knowledge of this book ....
Chapter I. Overview
the origin and basic role of node
Features of node:
1. Asynchronous I/O (Sending requests and processing requests do not interfere with each other)
2. Events and callback functions (node is event-driven)
3. Single Thread
4. Shared Platform (Linux and Windows)
Node's application scenario:
1. I/O intensive
2. Distributed Applications
Chapter II module mechanism
node is based on JavaScript, and JavaScript itself has many inherent weaknesses, and its mission is to serve the client, for server-side support (module system, standard library, standard interface, lack of package management system) , it is simply nothing, do not care. Fortunately, the COMMONJS specification is available, and its mission is to expect JavaScript to run anywhere.
Commonjs the definition of the module has three parts, namely: 1, module reference 2, module definition 3, module identification
-require
-exports
-module
1. Module reference:
var math = require (' math ');
2. Module definition:
// Math.js function () { var sum = 0; while (Sum <) { + = 1; } return
Then, require to introduce the module, you can invoke the defined properties and methods. require = = Exports
3. Module Identification:
arguments, strings, or paths passed to the Require method
Module Implementation of 2.2 node
The introduction of modules in node goes through three steps:
(1) path analysis
-- Core Module , FS http
-- file Module ,. Or. The starting relative path file module
--Absolute path module with/start
--Non-path-form built-in modules , such as Custom connect modules
(2) File location
--By Path
--by suffix name,. js,. node,. JSON
(3) Compile and execute
--JavaScript Core module, after the identifier analysis, directly into the memory, than the normal file module from the disk to find much faster
--C + + built-in module, binary, array, memory, using the binding () method to assist in loading the built-in module
How to write: Node_module () lowest--process.binding definition into memory
How to export: Hierarchical dependencies, built-in C + +-core module JavaScript---File modules
2.3 Packages with NPM
Module organization code, package Organization module
Package.json description file, dependencies: List of dependent packages
Release package, NPM publish <folder>
2.4 Front-end common module
The front and back end modules have different emphases. The front-end needs to load the server, the asynchronous loading module, the back-end of the module is local, with the use of synchronous loading.
COMMODJS Specification: Synchronous mode, for back end
AMD Spec: Asynchronous mode, for front end
CMD specification: A combination of people's self-creation, the former two, loading and defining similar AMD, module export and introduction to the definition of the near COMMONJS specification
Compatible with the definition of multiple specifications:
To allow the same module to run at the front and back, the following is achieved:
<< nodejs>> Reading notes--< a >