node-fs

13
http://www.flickr.com/photos/dippy_duck/4562866718 BarcelonaJS node-fs 30 January 2013 Bruno Pedro

Upload: bruno-pedro

Post on 05-Dec-2014

1.548 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: node-fs

http://www.flickr.com/photos/dippy_duck/4562866718

BarcelonaJS node-fs30 January 2013

Bruno Pedro

Page 2: node-fs

Bruno PedroWeb and Cloud Computing Technologist with over ten years’ experience. CTO of Nubera, the company behind GetApp and CloudWork.

http://brunopedro.com/

Page 3: node-fs

Summary• Why node-fs?

• Polymorphic approach

• Who’s using it?

• Future plans

• Questions

Page 4: node-fs

Why node-fs?

• recursively creating directories is a common problem

• different libraries and npm packages

• none of them was simple and easy to use

Page 5: node-fs

The solution• simple and easy to use library

• augments fs functionality

• polymorphic approach

• available as npm package

• should be part of node’s core!

Page 6: node-fs

Polymorphic approach• Function overloading

+mkdir()+mkdirSync()

fs

+mkdir()+mkdirSync()

node-fs

Page 7: node-fs

Polymorphic approach• Original fs functions

fs.mkdir  =  function  (path,  mode,  callback)

fs.mkdirSync  =  function  (path,  mode)

Page 8: node-fs

Polymorphic approach• Ad-hoc polymorphism

fs.mkdir  =  function  (path,  mode,  recursive,  callback)

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

Page 9: node-fs

Example usage

$  npm  install  node-­‐fs

Page 10: node-fs

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);

Page 11: node-fs

Who’s using it?• Alibaba.com

• Digital Repositoryof Ireland

• VirtuOz

Page 13: node-fs

Questions?

Thank you!