![]() |
VOOZH | about |
The file system module or fs module is an inbuilt module in Node js which is used to work with files on the computer. The functions of the module can be used by importing the fs module. The fs module can be included in the program by using the fs.writeSync() function of the filesystem module is the synchronous version of the write() method. It can be used for writing text as well as binary data onto the file.
Syntax:
fs.writeSync( fd, string, position, encoding )or
fs.writeSync( fd, buffer, offset, length, position )
Parameters:
Return value: Number of bytes written is returned.
Example:
Run index.js file using below command:
node index.js
Console Output:
File written successfully using writeSync() Text written on file: Welcome to GeeksforGeeks,starting from position: 0 Number of Bytes written: 24
Example:
Run index.js file using below command:
node index.js
Console Output:
File written successfully using writeSync() Buffer written on file: GeeksforGeeks: A computer science portal for geeks starting from position: 0 Number of Bytes written: 50
Reference: