1. Callback function
Node is an asynchronous event-driven platform, so we often need to use callback functions in our code.
Cases:
1 setTimeout (function() {2 console.log (' callback is called '); 3 },2000);
2. Standard callback function
The callback function format in node. JS is conventional, it has two parameters, the first argument is err, the second argument is Data,err is the error message, and data is the return.
Cases:
function (err,data) {}
3. Acquiring and using modules
In order to support rapid development, the node platform provides a large number of modules, encapsulating the different functions, then we will get the desired module, we come to introduce. In node, we can use the Require function with the following syntax:
(1) Module reference
var math = require ("math");
(2) Module definition
// math.js function () { var sum = 0, = 0, = arguments, = args.length; while (i<1) { + = args[i++] ; } return
In another file, when a module is introduced through the Require () method, the defined property or method can be called:
// program.js var math = require (' math '); function (val) { return math.add (val,1);};
(3) Module identification
Is the argument passed to the Require () method, which must be a string that conforms to the name of the small hump, or. The relative path to the beginning, or the absolute path, or the file name suffix. js.
Learning Documents:
http://nodeapi.ucdok.com/#/api/
Http://nodejs.cn/api
node. JS Learning Note (i)