New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

get-root-path

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-root-path

Get the closest parent folder containing a package.json file

3.0.1
latest
Source
npm
Version published
Weekly downloads
1.8K
-40.67%
Maintainers
0
Weekly downloads
 
Created
Source

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.

Keywords

path

FAQs

Package last updated on 08 Jan 2025

Did you know?

Socket

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.

Install

Related posts