Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Published in: Technology
  • Be the first to comment


  1. 1. Bruno Pedro 30 January 2013BarcelonaJS node-fs
  2. 2. Bruno PedroWeb and Cloud Computing Technologist withover ten years’ experience. CTO of Nubera,the company behind GetApp and CloudWork.
  3. 3. Summary• Why node-fs?• Polymorphic approach• Who’s using it?• Future plans• Questions
  4. 4. Why node-fs?• recursively creating directories is a common problem• different libraries and npm packages• none of them was simple and easy to use
  5. 5. The solution• simple and easy to use library• augments fs functionality • polymorphic approach• available as npm package• should be part of node’s core!
  6. 6. Polymorphic approach• Function overloading fs +mkdir() +mkdirSync() node-fs +mkdir() +mkdirSync()
  7. 7. Polymorphic approach• Original fs functions fs.mkdir  =  function  (path,  mode,  callback) fs.mkdirSync  =  function  (path,  mode)
  8. 8. Polymorphic approach• Ad-hoc polymorphism fs.mkdir  =  function  (path,  mode,  recursive,  callback) fs.mkdirSync  =  function  (path,  mode,  recursive)
  9. 9. Example usage $  npm  install  node-­‐fs
  10. 10. Example usagevar  fs  =  require(node-­‐fs);  ////  Example  with  recursion  -­‐-­‐  notice  the  parameter//  right  before  the  callback  function.//fs.mkdir(/tmp/example_dir/first/second,  0777,  true,  function  (err)  {    if  (err)  {        console.log(err);    }  else  {        console.log(Directory  created);    }});  ////  Synchronous  example  with  recursion.//fs.mkdirSync(/tmp/example_sync/first/second,  0777,  true);
  11. 11. Who’s using it?•• Digital Repository of Ireland• VirtuOz
  12. 12. Future plans• Add more fs operations • unlink, rmdir, chmod, chown, [lf]*stat• node-pfs: parallel fs operations• Wanna help? Fork node-fs!
  13. 13. Questions? Thank you!