Import the 'fs' module: Use the require() function to import the built-in 'fs' module in Node.js.
Define the data to be written: Create a variable and assign the data (e.g., a string or an object) to be written to the file.
Use the fs.writeFile() method: Call the writeFile() method on the 'fs' module, passing the file name, data, and encoding as parameters. Provide a callback function to handle any errors.
Handle errors (optional): Within the callback function, check for any errors returned by the writeFile() method and handle them appropriately.