
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
readfiletree
Advanced tools
Deserialize a file/directory tree into an object. Particularly useful for testing where you need to do a deepStrictEqual() on a simple tree of files. See mkfiletree for file tree serialization.
Node.js >= 20
Read the directory and the files it contains, recursively, and return an object representing the directory structure with nodes containing the utf8 string contents of each file.
Using both mkfiletree and readfiletree we can do the following:
import * as mkfiletree from 'mkfiletree'
import { readfiletree } from 'readfiletree'
const dir = await mkfiletree.makeTemp('testfiles',
{
'adir': {
'one.txt': '1\n2\n3\n',
'two.txt': 'a\nb\nc\n',
'deeper': {
'depths.txt': 'whoa...'
}
},
'afile.txt': 'file contents'
})
const obj = await readfiletree(dir)
console.log(obj)
The directory structure created above looks like the following:
$ find /tmp/testfiles11240-23530-r7rs3 -type f -exec sh -c "echo '\n{}: ' && cat '{}'" \;
/tmp/testfiles11240-23530-r7rs3/afile.txt:
file contents
/tmp/testfiles11240-23530-r7rs3/adir/deeper/depths.txt:
whoa...
/tmp/testfiles11240-23530-r7rs3/adir/two.txt:
a
b
c
/tmp/testfiles11240-23530-r7rs3/adir/one.txt:
1
2
3
And the output of the program should be the same as the input to mkfiletree:
{
'adir': {
'one.txt': '1\n2\n3\n',
'two.txt': 'a\nb\nc\n',
'deeper': {
'depths.txt': 'whoa...'
}
},
'afile.txt': 'file contents'
}
readfiletree is Copyright (c) 2012 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
FAQs
Serialize a tree of files and directories into object form
We found that readfiletree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.