Node.js is a platform built on the Chrome JavaScript runtime.
Node.js is an event-driven I/O server-side JavaScript environment based on Google's V8 engine. The V8 engine executes Javascript very quickly and has very good performance.
Node.js callback functions syntax
Node.js The direct manifestation of asynchronous programming is callbacks.
Asynchronous programming relies on callbacks, but it cannot be said that the program becomes asynchronous after using callbacks.
The callback function will be called after completing the task. Node uses a large number of callback functions. All Node APIs support callback functions.
For example, we can read a file while executing other commands. After the file reading is completed, we return the file content as a parameter of the callback function. This way there is no blocking or waiting for file I/O operations while executing code. This greatly improves the performance of Node.js and can handle a large number of concurrent requests.
Node.js callback functions example
Create the main.js file with the following code:
var fs = require("fs"); var data = fs.readFileSync('input.txt'); console.log(data.toString()); console.log("程序执行结束!");