VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-fs-fdatasyncsync-method/

⇱ Node.js fs.fdatasyncSync() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js fs.fdatasyncSync() Method

Last Updated : 23 Jul, 2025

The fs(File System) module enables interacting with the file system in a way modeled on standard POSIX functions, which means we can perform I/O operations with our Computer's file System. Like reading data from a file, writing data to a file, etc. All the file system operations have synchronous and asynchronous forms and mostly the asynchronous form takes a completion callback as its last argument.

The fs.fdatasyncSync() (Added in v0.1.96) method is the synchronous version of fs.fdatasync().

fs.fdatasync() method is an inbuilt API(Application Programming Interface) of the fs(File System) module which is similar to fs.fsync() method, fs.fsync() transfers ( or flushes) all modified data of the file to the disk memory so that all changed information can be retrieved even if the system crashes or rebooted, but fdatasync() method does not transfer or flush modified metadata unless that metadata is needed in order to allow a succeeding data write/read to be correctly handled.

Both fdatasyncSync() and fdatasync() methods reduce unnecessary disk activity.

Syntax:

// Require fs module at the top of this .js file
const fs = require('fs');

fs.fdatasyncSync(fd);

Parameter: fs.fdatasyncSync() method takes only one parameter.

  • fd<integer>: This an integer type value.

Example: In the main.js file, write the following code.

Run the file using node main.js

Output:

Writing 'data' in 'data.js'
Reference:https://nodejs.org/api/fs.html#fs_fs_fdatasyncsync_fd
Comment

Explore