Read directory into JSON tree module for node.
npm install dir-prop
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 | description | default | accept |
---|---|---|---|
exclude | excluded directory name | node_modules, .git | [array] |
recursion | recursion from root directory | true | boolean |
root | specific relative or absolute directory | __dirname | String |
Use with express server
options | description | default | accept |
---|---|---|---|
app | express app | app | |
method | http method for request param, otherwise will use default options param | get, post | |
template | use template if provided, otherwise will retuen raw json data | String |
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 {
...
}
}