Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
The 'parents' npm package is a utility that allows you to get an array of the directory paths from a given directory up to the root directory. It is useful for file system navigation and operations that require knowledge of a file or directory's ancestry.
Get parent directories
This feature allows you to retrieve an array of parent directories of a given path. The array starts with the immediate parent directory and ends with the root directory.
const parents = require('parents');
const dirs = parents('/usr/local/bin/node');
console.log(dirs); // ['/usr/local/bin', '/usr/local', '/usr', '/']
The 'path-parents' package provides similar functionality to 'parents' by returning an array of parent paths. It differs in its API and additional options for filtering the results.
The 'find-parent-dir' package finds the nearest parent directory that contains a given file or directory. It is similar to 'parents' but focuses on locating a specific file or directory in the ancestry rather than listing all parent directories.
The 'pkg-dir' package finds the root directory of a Node.js project or npm package. This is a more specialized use case compared to 'parents', which is more general in listing parent directories.
Return all the parent directories of a directory, inclusive of that directory.
var parents = require('parents');
var dirs = parents(__dirname);
console.dir(dirs);
[ '/home/substack/projects/node-parents/example',
'/home/substack/projects/node-parents',
'/home/substack/projects',
'/home/substack',
'/home',
'/' ]
var parents = require('parents');
var dir = 'C:\\Program Files\\Maxis\\Sim City 2000\\cities';
var dirs = parents(dir, { platform : 'win32' });
console.dir(dirs);
[ 'C:\\Program Files\\Maxis\\Sim City 2000\\cities',
'C:\\Program Files\\Maxis\\Sim City 2000',
'C:\\Program Files\\Maxis',
'C:\\Program Files',
'C:' ]
var parents = require('parents')
Return an array of the parent directories of dir
, including and starting with
dir
. If a dir
isn't specified, process.cwd()
will be used.
Optionally specify an opts.platform
to control whether the separator and paths
works the unixy way with '/'
or the windowsy way where sometimes things use
'/'
and sometimes they use '\\'
and also there are leading drive letters and
other exotic features. If opts.platform
isn't specified, process.platform
will be used. Anything that matches /^win/
will use the windowsy behavior.
With npm do:
npm install parents
MIT
FAQs
return all the parent directories for a directory
We found that parents 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.