HTTP Module Introduction
More features that support the HTTP protocol
Do not cache requests and responses
API comparison of the underlying processing flow-related, information analysis
HTTP related concept callbacks
The function is passed as a parameter to the execution function, and the parameter function is nested in the execution function.
function Learn (something) { console.log (something);} function We (callback,something) { something+ = ' is cool ' callback (something)}// named function We (Learn, ' Nodejs ')// anonymous functions We (function(something) { Console.log (Something)},' Hello ')
Synchronous/Asynchronous
asynchronous functions in JavaScript
// Executes once SetTimeout (function() { alert (' 1 ')},2000) within the specified interval
// repeated execution within the execution interval, but the alert needs to be closed without popping n setinterval (function() { alert (' 1 ')}, 2000)
Synchronous
The task is executed sequentially, waiting for the previous execution to complete before executing the next
// Sync var c=0function print () { console.log (c)}function Plus () { SetTimeout (function() { console.log (' aaa ') },+) C +=1;} Plus () print ()
Asynchronous
Each task has multiple callback functions, and the previous task does not perform the next task, but instead executes the callback function, and the latter task executes in the order in which the task is sorted, not waiting for the previous task to complete
// asynchronously executes the callback function after the task execution completes var c=0function print () { console.log (c)}function Plus (callback) { SetTimeout (function() { c+=1; Callback () }, console.log (' a ')}plus (print)
/ o
Data read and write on disk
Single Thread/multithreading
Only one request and response can be made at a time
Multiple requests and responses at the same time
Blocking/non-blocking
Blocking: Client waits for service side response
Non-blocking: The request does not respond to the other, after a period of time to request
Event
Click, move, and other actions
Event-driven
function is executed when the event occurs
Event-driven callbacks
callback function in the function
Event Loops
Dense task asynchronous execution put into loop queue, single thread constantly querying loop queue
05 MU class Network "Attack on node. JS Foundation (i)" HTTP concept advanced