Open In App

Node.js fs.fsyncSync() Method

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will be learning about fsyncSync() method in NodeJS. Before diving deep into the topic, let’s have a brief idea about what a fsync() method is.

Node.js provides us with a ‘fs’ module that helps us with both synchronous and asynchronous forms. An asynchronous form has a callback as the last argument whereas in case of synchronous, it only consists of the file descriptor. A fsync() function does not return any value but helps to get the file descriptor in a synchronous way. A fsyncSync() method is just the synchronized form of fsync(). It helps to synchronize the disc cache.

Syntax:

fs.fsyncSync(fd)

fd refers to the File Descriptor and its return value is undefined.

Parameter: File Descriptor.

Return Type: Undefined.

File descriptor is a number that uniquely identifies an open file in a computer. It provides an entry to the global file table that provides us with the location of that entry. Example : if the file descriptor is 3, it means that in the global file table it is saved as a read/write operation with offset : 12.

At first, we need to install ‘fs’ and ‘express’ module in our NodeJS project. 

npm install fs express --save

Create a file ‘example.txt’ inside your node.js project so that we can use any kind of operation for that file. After that write the necessary javascript code for our project.

example.txt

 


 
node app.js

OUTPUT


Last Updated : 07 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads