
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Convert an array of objects into a persistent or temporary directory structure
Convert an array of objects into a persistent or temporary directory structure.
fsify
creates a persistent or temporary directory structure from an array of objects. It's like the opposite of the Linux and Unix tree
command.
npm install fsify
A structure is an array of objects that represents a directory structure. Each object must contain information about a directory or file.
.
├── dirname
│ └── filename
└── filename
import fsify, { DIRECTORY, FILE } from 'fsify'
const structure = [
{
type: DIRECTORY,
name: 'dirname',
contents: [
{
type: FILE,
name: 'filename',
contents: 'data',
},
],
},
{
type: FILE,
name: 'filename',
contents: 'data',
},
]
fsify()(structure)
Structures can be nested to any depth. The following example creates a directory structure with two directories and a file in the innermost directory.
.
└── dirname
└── dirname
└── filename
import fsify, { DIRECTORY, FILE } from 'fsify'
const structure = [
{
type: DIRECTORY,
name: 'dirname',
contents: [
{
type: DIRECTORY,
name: 'dirname',
contents: [
{
type: FILE,
name: 'filename',
},
],
},
],
},
]
fsify()(structure)
Temporary structures can be created with persistent
set to false
. This will create a temporary structure that is removed when the process exits.
dirname/
└── filename
import fsify, { FILE } from 'fsify'
const structure = [
{
type: FILE,
name: 'filename',
},
]
fsify({
cwd: 'dirname/',
persistent: false,
})(structure)
Temporary structures can be cleaned up manually by calling the cleanup
method on the instance. This is useful if you want to create a temporary structure and remove it before the process exits. The cleanup happens synchronously.
dirname/
└── filename
import fsify, { FILE } from 'fsify'
const structure = [
{
type: FILE,
name: 'filename',
},
]
const instance = fsify({
persistent: false,
})
await instance(structure)
instance.cleanup()
tree
tree
is a Linux and Unix command that lists the contents of directories in a tree-like format. It's a helpful CLI to view the structure of your file system.
tree -J --noreport ./* > structure.json
import fsify from 'fsify'
import structure from './structure.json' assert { type: 'json' }
fsify()(structure)
import fsify from 'fsify'
const instance = fsify()
import fsify from 'fsify'
const instance = fsify({
cwd: process.cwd(),
persistent: true,
force: false,
})
options
{?Object}
Options.
cwd
{?String}
Custom relative or absolute path. Defaults to process.cwd()
.persistent
{?Boolean}
Keep directories and files even when the process exists. Defaults to true
.force
{?Boolean}
Allow deleting the current working directory and outside. Defaults to false
.{Function}({?Array})
fsify instance.import fsify, { FILE } from 'fsify'
const structure = [
{
type: FILE,
name: 'filename',
},
]
const instance = fsify()
const parsedStructure = instance(structure)
structure
{?Array}
Array of objects containing information about a directory or file.{Promise<Array>}
A promise that resolves a structure. Equal to the input structure, but parsed and with a absolute path as the name.A structure is an array of objects that represents a directory structure. Each object must contain information about a directory or file.
The structure …
.
├── dirname
│ └── filename
└── filename
… is equal to …
import { DIRECTORY, FILE } from 'fsify'
const structure = [
{
type: DIRECTORY,
name: 'dirname',
contents: [
{
type: FILE,
name: 'filename',
contents: 'data',
},
],
},
{
type: FILE,
name: 'filename',
contents: 'data',
},
]
A directory must have the type
of a directory and a name
. It can also contain another nested structure in its contents
and a mode
.
import { DIRECTORY } from 'fsify'
const directory = {
type: DIRECTORY,
name: 'dirname',
mode: 0o777,
contents: [],
}
A file must have the type
of a file and a name
. It can also contain contents
(data of the file). encoding
, mode
and flag
will be passed directly to fs.writeFile
.
import { FILE } from 'fsify'
const file = {
type: FILE,
name: 'filename',
contents: 'data',
encoding: 'utf8',
mode: 0o666,
flag: 'w',
}
[6.0.0] - 2025-07-05
Modernized codebase with ESM modules, less dependencies, updated Node.js support and common code style.
import fsify from 'fsify'
)FILE
and DIRECTORY
constants can now be imported from the main module (e.g. import { FILE, DIRECTORY } from 'fsify'
)FAQs
Convert an array of objects into a persistent or temporary directory structure
The npm package fsify receives a total of 98 weekly downloads. As such, fsify popularity was classified as not popular.
We found that fsify 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.