node. jsnode is a platform and a language. It is a platform or running environment, can let JS run on the server side, because it encapsulates the V8 engine (engine, the ability to parse the JS code into a computer can understand the language), can let JS run on other platforms, and not just run on the browser. It is a server-side language, similar to Php,java. JS is an explanatory language, not compiled, the computer does not recognize, so Google V8 engine compiled JS code.
callback functionFunction A has a parameter b,b is a function that executes B when function a finishes. Function B is passed to function a in the form of a parameter.
node. JS features(Single-threaded, asynchronous, non-blocking) (instantaneous throughput is very large) asynchronous, non-blocking: blocking (a request must be executed to execute the second request), non-blocking (a callback is executed once a request has been made.) Multiple requests are made, and several callbacks are executed). Single threaded: One core inside runs multi-threaded: One core runs multiple tasks, and a process has a lot of threads.
ModuleFile and module one by one corresponding, a file is a module, exposed to a number of external module.exports, exposed to a exports
JS single-threaded and asynchronousSingle-threaded and asynchronous does not have to be a language feature at the same time. JS chose to become a single-threaded language, so it can not be asynchronous, but JS hosting environment (such as browser, Node) is multi-threaded, the host environment in some way (event-driven) to make JS with the asynchronous properties. JS is a single-threaded language, the browser is only assigned to JS a main thread, and then for some more time-consuming tasks in addition to open up a thread, this line thread task is asynchronous.
node. JS RoutingRespond differently to different requests,
Try--catchPut the code in a try, and if the code inside does not have an error handling mechanism, the error is caught by the catch and the Catch method is executed.
SummaryHttp:var http = require ("http"),//nodejs Load module method, HTTP system module dedicated to node creation service. The introduction of HTTP module can realize LAN communication, create service, http://request, etc. Http.createserver (function () {})//create service Url:var URL = require (' URL '); Url.parse (Req.url); The URL module is introduced to convert the requested URL into an object.
node. JS Learning Note One