Skip to content
Advertisement

Convert a directory structure in the filesystem to JSON with Node.js

I have a file structure like this:

JavaScript

I would like to, using Javascript and Node.js, listen to this root directory and all sub directories and create a JSON which mirrors this directory structure, each node contains type, name, path, and children:

JavaScript

Here’s a coffeescript JSON:

JavaScript

how to get this json data format in django views?(python)

Advertisement

Answer

Here’s a sketch. Error handling is left as an exercise for the reader.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement