Bruno Pedro
                    30 January 2013
BarcelonaJS          node-fs
              http://www.flickr.com/photos/dippy_duck/4562866718
Bruno Pedro
Web and Cloud Computing Technologist with
over ten years’ experience. CTO of Nubera,
the company behind GetApp and CloudWork.

http://brunopedro.com/
Summary
• Why node-fs?
• Polymorphic approach
• Who’s using it?
• Future plans
• Questions
Why node-fs?
• recursively creating directories is a
  common problem
• different libraries and npm packages

• none of them was simple and easy to use
The solution
• simple and easy to use library
• augments fs functionality
 • polymorphic approach
• available as npm package

• should be part of node’s core!
Polymorphic approach
• Function overloading
             fs
       +mkdir()
       +mkdirSync()




         node-fs
       +mkdir()
       +mkdirSync()
Polymorphic approach
• Original fs functions
  fs.mkdir	
  =	
  function	
  (path,	
  mode,	
  callback)



  fs.mkdirSync	
  =	
  function	
  (path,	
  mode)
Polymorphic approach
• Ad-hoc polymorphism
  fs.mkdir	
  =	
  function	
  (path,	
  mode,	
  recursive,	
  callback)



  fs.mkdirSync	
  =	
  function	
  (path,	
  mode,	
  recursive)
Example usage



 $	
  npm	
  install	
  node-­‐fs
Example usage
var	
  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);
Who’s using it?
• Alibaba.com

• Digital Repository
  of Ireland


• VirtuOz
Future plans
• Add more fs operations
 • unlink, rmdir, chmod, chown, [lf]*stat

• node-pfs: parallel fs operations

• Wanna help? Fork node-fs!
Questions?

 Thank you!

node-fs

  • 1.
    Bruno Pedro 30 January 2013 BarcelonaJS node-fs http://www.flickr.com/photos/dippy_duck/4562866718
  • 2.
    Bruno Pedro Web andCloud Computing Technologist with over ten years’ experience. CTO of Nubera, the company behind GetApp and CloudWork. http://brunopedro.com/
  • 3.
    Summary • Why node-fs? •Polymorphic approach • Who’s using it? • Future plans • Questions
  • 4.
    Why node-fs? • recursivelycreating directories is a common problem • different libraries and npm packages • none of them was simple and easy to use
  • 5.
    The solution • simpleand easy to use library • augments fs functionality • polymorphic approach • available as npm package • should be part of node’s core!
  • 6.
    Polymorphic approach • Functionoverloading fs +mkdir() +mkdirSync() node-fs +mkdir() +mkdirSync()
  • 7.
    Polymorphic approach • Originalfs functions fs.mkdir  =  function  (path,  mode,  callback) fs.mkdirSync  =  function  (path,  mode)
  • 8.
    Polymorphic approach • Ad-hocpolymorphism fs.mkdir  =  function  (path,  mode,  recursive,  callback) fs.mkdirSync  =  function  (path,  mode,  recursive)
  • 9.
    Example usage $  npm  install  node-­‐fs
  • 10.
    Example usage var  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.
    Who’s using it? •Alibaba.com • Digital Repository of Ireland • VirtuOz
  • 12.
    Future plans • Addmore fs operations • unlink, rmdir, chmod, chown, [lf]*stat • node-pfs: parallel fs operations • Wanna help? Fork node-fs!
  • 13.