To read the contents of a file asynchronously using the fs (File System) module in Node.js, the method used is fs.readFile(). This method allows you to read the file's contents without blocking the execution of the rest of your code.
Here's a basic example:
const fs = require('fs');
fs.readFile('path/to/file.txt', 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
console.log('File contents:', data);
});