Home >Web Front-end >JS Tutorial >Node.js asynchronous non-blocking callback function

Node.js asynchronous non-blocking callback function

黄舟
黄舟Original
2017-01-17 15:37:041418browse

Callback function (asynchronous non-blocking)

main.js file

[code]// 引入文件模块
var fs = require('fs');
// 读取test.txt文件
fs.readFile('test.txt', function (err, data) {
    if (err) return console.log(err);
    console.log(data.toString());
});
console.log('程序执行完毕');

Analysis: execute the program first, then read the file

Node.js asynchronous non-blocking callback function

The above is the content of Node.js asynchronous non-blocking callback function. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Node.js No-frills npmNext article:Node.js No-frills npm