Q:

Write a node.js program to get files or directories of a directory in JSON format

belongs to collection: Node.js programming Exercises

0

Write a node.js program to get files or directories of a directory in JSON format

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution

JSON (JavaScript Object Notation) is a lightweight, open standard, data-interchange format. It is easy to read and write for humans. It is used primarily to transmit data between web application and server. The given example asynchronously convert directory tree structure into a JavaScript object.

Install with NPM

npm install dir-to-json --save
var dirToJson = require('dir-to-json');
 
dirToJson( "./album", function( err, dirTree ){
    if( err ){
        throw err;
    }else{
        console.log( dirTree );
    }
});
 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How does node connect to database in node.js?... >>
<< There is a given object, write node.js program to ...