Node.js directory parsings

Wercker is a Docker-Native CI/CD Automation platform for Kubernetes & Microservice Deployments

Yoshua Wuyts
Yoshua Wuyts
January 10, 2015

Today we’ve released two Node.js modules for processing directory structures. In this update we’ll highlight what they do.

directory-to-object (source)

directory-to-object (dto) is an algorithm that recursively walks a directory asynchronously and returns a representation of the directory. It’s used as followed:

const dto  = require('directory-to-object')
const path = require('path')

dto(path.resolve('./test'), (err, res) => console.log(res))
// {
//   fooDir: [file1, file2, file3],
//   barDir: [file4, file5, file6]
// }

directory-to-json (source)

directory-to-json (dtj) is an small wrapper around dto that asynchronously writes the created object to a JSON file so it can later be statically consumed. The interface looks like this:

const dtj = require('directory-to-json')

dtj('./mydir', './outfile.json', (err) => console.log(err))

Wrapping up

We’re currently refactoring some of our static sites, and we needed a simple way to get a JSON representation that can be passed to the client. Since we thought this might be useful for others we’re sharing it with the world. Enjoy!

Have any questions? Drop us a line at pleasemailus[at]


Topics: Product, Integrations