Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
The make-dir npm package is designed to simplify the process of creating directories along with their subdirectories in a Node.js environment. It wraps around the native fs.mkdir and fs.mkdirSync methods, providing a promise-based API and ensuring that all necessary parent directories are created if they do not exist. This is particularly useful for setting up complex directory structures with minimal code.
Creating a directory with promise
This feature allows for the creation of a directory and all necessary parent directories using a promise-based API. It's useful for asynchronous directory creation without blocking the main thread.
const makeDir = require('make-dir');
makeDir('path/to/dir').then(path => {
console.log(`Directory created at ${path}`);
});
Creating a directory synchronously
This feature provides a synchronous method to create a directory and all necessary parent directories. It's useful when you need to ensure a directory is created before proceeding with the execution of subsequent code.
const makeDir = require('make-dir');
const path = makeDir.sync('path/to/dir');
console.log(`Directory created at ${path}`);
mkdirp is a package with functionality similar to make-dir, allowing for the creation of directories and their parents if they don't exist. The main difference is that mkdirp has been around longer and was more widely used before Node.js introduced native support for recursive directory creation in version 10.12.0. make-dir, however, offers a more modern promise-based API, making it a better fit for asynchronous workflows.
fs-extra extends the Node.js built-in fs module, adding file system methods that aren't included in the standard library, such as recursive directory creation. While fs-extra includes functionality similar to make-dir, it's a more comprehensive package that offers a wide range of file system operations, making it a heavier dependency if directory creation is the only required feature.
Make a directory and its parents if needed - Think
mkdir -p
mkdirp
mkdirp
issues: #96 #70 #66fs.mkdir/mkdirSync
recursive
option in Node.js >=10.12.0 unless overridden$ npm install make-dir
$ pwd
/Users/sindresorhus/fun
$ tree
.
const makeDir = require('make-dir');
(async () => {
const path = await makeDir('unicorn/rainbow/cake');
console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
})();
$ tree
.
└── unicorn
└── rainbow
└── cake
Multiple directories:
const makeDir = require('make-dir');
(async () => {
const paths = await Promise.all([
makeDir('unicorn/rainbow'),
makeDir('foo/bar')
]);
console.log(paths);
/*
[
'/Users/sindresorhus/fun/unicorn/rainbow',
'/Users/sindresorhus/fun/foo/bar'
]
*/
})();
Returns a Promise
for the path to the created directory.
Returns the path to the created directory.
Type: string
Directory to create.
Type: object
Type: integer
Default: 0o777 & (~process.umask())
Directory permissions.
Type: object
Default: require('fs')
Use a custom fs
implementation. For example graceful-fs
.
Using a custom fs
implementation will block the use of the native recursive
option if fs.mkdir
or fs.mkdirSync
is not the native function.
FAQs
Make a directory and its parents if needed - Think `mkdir -p`
The npm package make-dir receives a total of 73,076,263 weekly downloads. As such, make-dir popularity was classified as popular.
We found that make-dir 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 has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.