JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 40037
  • Score
    100M100P100Q155219F
  • License MIT

Get the closest parent folder containing a package.json file

Package Exports

  • get-root-path
  • get-root-path/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (get-root-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Get Root Path - NodeJS

  • Stop counting dots - get the project root path with a single import
    • (...or a single require if you're oldskool)
  • Memoizes the result for rapid lookups after initial run

What is the root path?

  • The nearest directory up the file system tree with a package.json file.

Installation

npm install --save get-root-path

Basic usage

import { rootPath } from 'get-root-path';

path.join(rootPath, 'build/app/client');
  • If you set the APP_ROOT_PATH environment variable, it will return the value of APP_ROOT_PATH as the root path instead.

Real-world usage

import { rootPath } from 'get-root-path';

const app = express()
    .use('/', express.static(path.join(rootPath, 'build/app/client')));

What it does

  • No magic: it just finds the nearest parent (ancestor?) directory containing a package.json file
    • 99% of the time this will be the project root of the file doing the lookup.