top of page

Files and Directories in Node.js.

  • Writer: VC Healy
    VC Healy
  • Oct 8, 2020
  • 1 min read

I now know how to work with files and directories in Node.js.


In this module, I learned how to read files and directories, create files and directories, and write data to files.


A few things from this module:

  • Always use the promises namespace on the built-in modules. Then use the async and await operators to make code synchronous without blocking program execution.

  • Whenever creating a directory, make sure to wrap it in a try/catch. The default behavior in Node.js is to throw an error when trying to create a directory that already exists. Just want to check if a directory exists or not, can use the stat method. Note that this method does not exist on the promises namespace, but on the main fs object.

  • If there is a need to parse other file types, check out the packages on npmjs.org. For example, use the papaparse package for .csv files. Use the fixy package for fixed-width files.



 
 
 

Comentarios


© 2020 by Vincent Healy. Proudly created with Wix.com

bottom of page