Node.js uses callbacks, Promises, and async/await to handle asynchronous operations. Callbacks are a common pattern, but Promises and async/await provide more readable and maintainable code.
質問 7. What is the purpose of the 'global' object in Node.js?
The 'global' object represents the global scope in Node.js. Variables declared in the global scope are available globally to all modules in the application.
Example:
global.myVariable = 'Hello';
役に立ちましたか?
コメントを追加コメントを見る
質問 8. Explain the role of the 'require' function in Node.js.
The 'require' function is used to include modules in Node.js. It is the way to import functionality from other modules.
Example:
const fs = require('fs');
役に立ちましたか?
コメントを追加コメントを見る
質問 9. What is the purpose of the 'process' object in Node.js?
The 'process' object is a global object that provides information about the current Node.js process. It can be used to get information about the environment, control the process, and handle signals.
Example:
console.log(process.env.NODE_ENV);
役に立ちましたか?
コメントを追加コメントを見る
質問 10. Explain the difference between 'process.nextTick()' and 'setImmediate()' in Node.js.
'process.nextTick()' and 'setImmediate()' are used to execute a callback function in the next iteration of the event loop. 'process.nextTick()' has a higher priority and runs before 'setImmediate()'.