How will you read a file using Node?


Following is the syntax of one of the methods to read from a file:, buffer, offset, length, position, callback)

This method will use file descriptor to read the file, if you want to read file using file name directly then you should use another method available.


Here is the description of the parameters used:

  • fd - This is the file descriptor returned by file method.

  • buffer - This is the buffer that the data will be written to.

  • offset - This is the offset in the buffer to start writing at.

  • length - This is an integer specifying the number of bytes to read.

  • position - This is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.

  • callback - This is the callback function which gets the three arguments, (err, bytesRead, buffer).


© 2017