In fs-extra module, you can use the openSync function to open a file and get a file descriptor. Here's how to use the openSync function:
index.tsx176 chars9 lines
In the code above, the openSync function takes two arguments:
r: Opens file for reading. An exception occurs if the file does not exist.r+: Opens file for reading and writing. An exception occurs if the file does not exist.w: Opens file for writing. The file is created (if it does not exist) or truncated (if it exists).w+: Opens file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).a: Opens file for appending. The file is created if it does not exist.a+: Opens file for reading and appending. The file is created if it does not exist.In the example above, the flag w is used, which means the file is opened for writing. Also, note that the function is called inside a try block and any errors are caught in the catch block.
gistlibby LogSnag