0.1.1 • Published 8 years ago

dir-prop v0.1.1

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

Read directory into JSON tree module for node.

Installation

npm install dir-prop

Usage

const { dirProp } = require('dir-prop');
dirProp({
  root: path.join(__dirname, '../')
}).then((data) => {
  console.log(data);
});

Use with express server (Demo)

const { dirServer } = require('dir-prop');

app.use(express.static(path.join(__dirname, '../'),
  { dotfiles: 'allow' }));

app.use('/', dirServer({
  root: path.join(__dirname, '../'),
  template: true
}));

Options

optionsdescriptiondefaultaccept
excludeexcluded directory namenode_modules, .gitarray
recursionrecursion from root directorytrueboolean
rootspecific relative or absolute directory__dirnameString

Use with express server

optionsdescriptiondefaultaccept
appexpress appapp
methodhttp method for request param, otherwise will use default options paramget, post
templateuse template if provided, otherwise will retuen raw json dataString

dir to prop

root
  |- demo
      |- demo
  |- src
      |- index.js
      ...
  |- README.md
  ...

to

{
  demo: {
    demo: Stats { /* fs.stat */
      dev: 16777220,
      mode: 33188,
      nlink: 1,
      ...
    }
  },
  src : {
    'index.js': Stats {
      ...
    },
    ...
  },
  'README.md': Stats {
    ...
  }
}