![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
find-parent-dir
Advanced tools
Finds the first parent directory that contains a given file or directory.
The find-parent-dir npm package is a utility for finding the parent directory of a given directory that contains a specific file or directory. It is useful for tasks such as locating configuration files or project root directories in a file system hierarchy.
Find Parent Directory Containing a Specific File
This feature allows you to find the parent directory that contains a specific file, such as 'package.json'. The code sample demonstrates how to use the findParentDir function to locate the parent directory of the current directory (__dirname) that contains 'package.json'.
const findParentDir = require('find-parent-dir');
findParentDir(__dirname, 'package.json', (err, dir) => {
if (err) {
console.error(err);
} else {
console.log('Parent directory containing package.json:', dir);
}
});
Find Parent Directory Containing a Specific Directory
This feature allows you to find the parent directory that contains a specific directory, such as 'node_modules'. The code sample demonstrates how to use the findParentDir function to locate the parent directory of the current directory (__dirname) that contains 'node_modules'.
const findParentDir = require('find-parent-dir');
findParentDir(__dirname, 'node_modules', (err, dir) => {
if (err) {
console.error(err);
} else {
console.log('Parent directory containing node_modules:', dir);
}
});
The find-up package is a utility for finding a file or directory by walking up parent directories. It is similar to find-parent-dir but offers more flexibility by allowing you to search for files or directories with a specific name or pattern. It also supports promises and synchronous operations.
The locate-path package is used to find the first instance of a file or directory in a list of paths. It is similar to find-parent-dir in that it helps locate files or directories, but it focuses on searching through a list of paths rather than walking up the directory tree.
The pkg-up package is a specialized utility for finding the closest package.json file by walking up parent directories. It is similar to find-parent-dir but is specifically designed for locating package.json files, making it a more focused tool for Node.js projects.
Finds the first parent directory that contains a given file or directory.
npm install find-parent-dir
// assuming this is called from a file in a subdirectory of /myprojects/foo which contains .git directory
var findParentDir = require('find-parent-dir');
findParentDir(__dirname, '.git', function (err, dir) {
// has err if some file access error occurred
console.log(dir); // => /myprojects/foo/
// if parent dir wasn't found, dir is null
})
// Same using `sync` method
var dir;
try {
dir = findParentDir.sync(__dirname, '.git');
console.log(dir); // => /myprojects/foo/
// if parent dir wasn't found, dir is null
} catch(err) {
console.error('error', err);
}
FAQs
Finds the first parent directory that contains a given file or directory.
The npm package find-parent-dir receives a total of 0 weekly downloads. As such, find-parent-dir popularity was classified as not popular.
We found that find-parent-dir demonstrated a not healthy version release cadence and project activity because the last version was released 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
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.