Gathering detailed insights and metrics for app-root-path
Gathering detailed insights and metrics for app-root-path
Gathering detailed insights and metrics for app-root-path
Gathering detailed insights and metrics for app-root-path
@types/app-root-path
Stub TypeScript definitions entry for app-root-path, which provides its own types definitions
lup-root
Determines absolute path to project root and main file
@itrocks/app-dir
A Node.js library to determine the root directory of your project
electron-manager
An NPM module with tools, helper functions, and utilities for building a flawless Electron app 🚀
npm install app-root-path
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
605 Stars
101 Commits
30 Forks
7 Watchers
3 Branches
6 Contributors
Updated on Jun 14, 2025
Latest Version
3.1.0
Package Id
app-root-path@3.1.0
Unpacked Size
14.61 kB
Size
5.92 kB
File Count
8
NPM Version
8.13.2
Node Version
18.6.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Please Note: Due to the very limited scope of this module, I do not anticipate needing to make very many changes to it. Expect long stretches of zero updates—that does not mean that the module is outdated.
This simple module helps you access your application's root path from anywhere in the application without resorting to relative paths like require("../../path")
.
1$ npm i -S app-root-path
To simply access the app's root path, use the module as though it were a string:
1var appRoot = require('app-root-path'); 2var myModule = require(appRoot + '/lib/my-module.js');
Side note: the module actually returns an object, but that object implements the
toString
method, so you can use it as though it were a string. There are a few edge cases where this might not be the case (most notablyconsole.log
), but they shouldn't affect actual use of the module, where you're almost always concatenating with an additional string.
A helper function is also provided:
1var reqlib = require('app-root-path').require; 2var myModule = reqlib('/lib/my-module.js');
It's a little hacky, but you can also put this method on your application's global
object to use it everywhere in your project:
1// In app.js 2global.reqlib = require('app-root-path').require; 3 4// In lib/module/component/subcomponent.js 5var myModule = reqlib('/lib/my-module.js');
Finally, you can also just resolve a module path:
1var myModulePath = require('app-root-path').resolve('/lib/my-module.js');
You can explicitly set the path, using the environmental variable APP_ROOT_PATH
or by calling require('app-root-path').setPath('/my/app/is/here')
No need to read this unless you're curious—or you run into a (very unlikely) case where the module does not work as expected.
This module uses two different methods to determine the app's root path, depending on the circumstances.
If the module is located inside your project's directory, somewhere within the node_modules
directory (whether directly, or inside a submodule), we effectively do (the actual code takes cross-platform path names/etc into consideration):
1path.resolve(__dirname).split('/node_modules')[0];
This will take a path like /var/www/node_modules/submodule/node_modules/app-root-path
and return /var/www
. In nearly all cases, this is just what you need.
The node module loader will also look in a few other places for modules (for example, ones that you install globally with npm install -g
). These can be in one of:
$HOME/.node_modules
$HOME/.node_libraries
$PREFIX/lib/node
Or, anywhere in the NODE_PATH
environmental variable (see documentation).
In these cases, we fall back to an alternate trick:
1path.dirname(require.main.filename);
When a file is run directly from Node, require.main
is set to that file's module
. Each module has a filename
property that refers to the filename of that module, so by fetching the directory name for that file, we at least get the directory of file passed to node
. In some cases (process managers and test suites, for example) this doesn't actually give the correct directory, though, so this method is only used as a fallback.
If your module is installed as a global CLI, for example in /usr/local/lib/node_modules/yourmodule
, then
require.main.filename
will report /usr/local/lib/node_modules/yourmodule/bin
, which is probably not what
you want. app-root-path
is aware of this edge-case and will strip the /bin
automatically.
require.main
is missing (ESM imports)require()
statements during packaging.module.require
to appRootPath.require
(which has been deprecated for a while)setPath()
did not update require('app-root-path').path
resolve()
function so that it's not called multiple timesrequire()
method to the appRootPath.require()
function. Which it's true that each module has its own require()
method, in practice it doesn't matter, and it's much simpler this way.When using semantic-release, the preferred method for commits is:
git add …
git cz
(see commitizen)git push
This helps ensure that commits match the expected format. Commits to master
will cause releases.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More