npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

project-dir

v0.1.4

Published

Search the project's root directory.

Readme

node-project-dir

Build Status Version License

NPM

Search the project's root directory.

Install

npm install project-dir

Documentation

How to use

myProject/
├── .git
├── node_modules
├── aaaa
│   └── bbbb
└── abcd
    └── efgh

require

const ProjectDir = require('project-dir');

on NodeJS

const myProject = new ProjectDir('./', 'node_modules')

console.log(myProject.basedir); // => '/home/user/myProject'
console.log(myProject.wd); // => '/home/user/myProject'

on git repository

const myProject = new ProjectDir('./', '.git')

console.log(myProject.basedir); // => '/home/user/myProject'
console.log(myProject.wd); // => '/home/user/myProject'

make sure NodeJS with git repository

const myProject = new ProjectDir('./', ['node_modules', '.git'])

console.log(myProject.basedir); // => '/home/user/myProject'
console.log(myProject.wd); // => '/home/user/myProject'

set basename

console.log(myProject.basename); // => ['node_modules', '.git']

myProject.basename = '.git'

console.log(myProject.basename); // => '.git'

set basedir

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'

set wd (working directory)

// 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'

resolve

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'

retrieve

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'

parse

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'
}

equal

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

toRoot

let paths = [];
myProject.toRoot('/abcd/efgh', (curPath) => paths.push(curPath));
console.log(curPath); // => ['/abcd/efgh', '/abcd']

API

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.

getter/setter

  • basename <Query> : get/set basename for dominating file.
  • basedir <Path> : get/set project's base directory.
  • wd <Path> : get/set project's working directory.

methods

  • resolve(<ProjectPath>) -> <Path> : Resolving path based on basedir
  • retrieve(<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.

Unit Test

Dev Depencencies

Test

npm test