
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
project-dir
Advanced tools
Search the project's root directory.
npm install project-dir
myProject/
├── .git
├── node_modules
├── aaaa
│ └── bbbb
└── abcd
└── efgh
const ProjectDir = require('project-dir');
const myProject = new ProjectDir('./', 'node_modules')
console.log(myProject.basedir); // => '/home/user/myProject'
console.log(myProject.wd); // => '/home/user/myProject'
const myProject = new ProjectDir('./', '.git')
console.log(myProject.basedir); // => '/home/user/myProject'
console.log(myProject.wd); // => '/home/user/myProject'
const myProject = new ProjectDir('./', ['node_modules', '.git'])
console.log(myProject.basedir); // => '/home/user/myProject'
console.log(myProject.wd); // => '/home/user/myProject'
console.log(myProject.basename); // => ['node_modules', '.git']
myProject.basename = '.git'
console.log(myProject.basename); // => '.git'
myProject.basedir = './abcd'; // => '/home/user/myProject'
myProject.wd; // => '/home/user/myProject/abcd'
myProject.basedir = './abcd/efgh'; // => '/home/user/myProject'
myProject.wd; // => '/home/user/myProject/abcd/efgh'
// root
myProject.wd = '/'; // => '/home/user/myProject'
// relative path
myProject.wd = 'abcd'; // => '/home/user/myProject/abcd'
myProject.wd = 'efgh'; // => '/home/user/myProject/abcd/efgh'
myProject.wd = '../'; // => '/home/user/myProject/abcd'
myProject.wd = '/aaaa'; // => '/home/user/myProject/aaaa'
myProject.wd = '/';
myProject.resolve('abcd'); // => '/home/user/myProject/abcd'
myProject.wd = '/aaaa';
myProject.resolve('bbbb'); // => '/home/user/myProject/aaaa/bbbb'
myProject.wd = '/aaaa';
myProject.resolve('/abcd'); // => '/home/user/myProject/abcd'
myProject.retrieve('/home/user/myProject/abcd'); // => '/abcd'
myProject.retrieve('/home/user/myProject/abcd/efgh'); // => '/abcd/efgh'
myProject.retrieve('/home/user/myProject'); // => '/'
myProject.retrieve('/home/user'); // => 'null'
myProject.parse('/abcd');
{
root: '/home/user/myProject',
names: '.git',
wd: '/home/user/myProject',
path: 'abcd',
abs: '/abcd',
realPath: '/home/user/myProject/abcd'
}
myProject.wd = '/abcd';
myProject.parse('efgh');
{
root: '/home/user/myProject',
names: '.git',
wd: '/home/user/myProject/abcd',
path: 'efgh',
abs: '/abcd/efgh',
realPath: '/home/user/myProject/abcd/efgh'
}
myProject.wd = '/abcd'
console.log(myProject.wd); // => '/home/user/myProject/abcd'
myProject.equal('/abcd/efgh', 'efgh'); // => true
myProject.equal('/aaaa', '../aaaa'); // => true
myProject.equal('/abcd', 'abcd'); // => false
let paths = [];
myProject.toRoot('/abcd/efgh', (curPath) => paths.push(curPath));
console.log(curPath); // => ['/abcd/efgh', '/abcd']
Don't confuse ProjectPath argument. It has a difference meaning with normal path.
When the argument takes ProjectPath, do not use absolute path in real file system.
This moudle handles root as sub directory of base directory when argument is ProjectPath.
eg. If base directory is "/home/user/abcd", the Path's "/efgh" means "/efgh" and the ProjectPath's "/efgh" means "/home/user/abcd/efgh".
constructor(<Path>, <Query>) : Search a Query matched directory from Path to root path. and set basedir.basename <Query> : get/set basename for dominating file.basedir <Path> : get/set project's base directory.wd <Path> : get/set project's working directory.resolve(<ProjectPath>) -> <Path> : Resolving path based on basedirretrieve(<Path>) -> <ProjectAbsPath> : Retrieving project path from absolute real path.parse(<ProjectPath>) -> <Object> : parsing path based on basedir. below output is result of path(+ sign means path.resolve, * sign means path.relative, path means argument, others are property name).{
root: <basedir>,
names: <basename>,
wd: <wd>,
path: <wd*path>,
abs: <basedir*(wd+path)>,
realPath: <wd+path>
}
equal(<ProjectPath>, <ProjectPath>) -> <boolean> : Compare with two project path is same.toRoot(<ProjectPath>, [<Object>, ]<Function>) : Recursively access from ProjectPath to basedir and send an argument of current path to Function.npm test
FAQs
Search the project's root directory.
We found that project-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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.