How many types of API functions are available in Node.js?

There are two types of API functions in Node.js:

  • Asynchronous, Non-blocking functions
  • Synchronous, Blocking functions

In Node.js, there are primarily two types of API functions:

  1. Asynchronous, Non-blocking Functions: These functions do not block the execution of the code. They typically accept a callback function as an argument to be executed once the operation is completed or an event occurs. Examples include functions like fs.readFile(), http.get(), and setTimeout().
  2. Synchronous, Blocking Functions: These functions block the execution of the code until the operation is completed. They return the result directly without using callbacks. Examples include functions like fs.readFileSync() and http.request().

In general, it’s important to favor asynchronous, non-blocking functions in Node.js to ensure scalability and responsiveness in applications.