Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
app-root-dir
Advanced tools
Package description
The app-root-dir npm package is a simple utility that helps you find the root directory of your Node.js application. This can be particularly useful when you need to access files or directories relative to the root of your project, regardless of where your script is being executed from.
Get the root directory
This feature allows you to get the root directory of your Node.js application. The code sample demonstrates how to use the `get` method from the app-root-dir package to retrieve and print the root directory path.
const appRootDir = require('app-root-dir').get();
console.log(appRootDir);
Set the root directory
This feature allows you to set a custom root directory for your Node.js application. The code sample demonstrates how to use the `set` method to define a new root directory and then retrieve it using the `get` method.
const appRootDir = require('app-root-dir');
appRootDir.set('/path/to/new/root');
console.log(appRootDir.get());
The app-root-path package provides similar functionality to app-root-dir by allowing you to easily access the root directory of your application. It also offers additional features like resolving paths relative to the root directory. Compared to app-root-dir, app-root-path is more feature-rich and has a more active maintenance history.
The find-root package helps you locate the root directory of your project by searching for a specific file (like package.json) up the directory tree. This package is more flexible in terms of defining what constitutes the root directory, but it requires a bit more configuration compared to app-root-dir.
Readme
Simple module to infer the root directory of the currently running node application
// get the application's root directory
var appRootDir = require('app-root-dir').get();
// set the application's root directory
// (this will set a global so that no matter
// how many instances of app-root-dir module are
// installed, they will all return the same
// directory)
require('app-root-dir').set(__dirname);
The following strategy is used to find the application's root directory (the directory in your project that contains the main package.json file):
process.cwd()
then use process.cwd()
as the application root directory.For example, consider this directory structure for the scenarios below:
Application is ran as:
node server.js
The application root directory will be my-project because package.json exists at process.cwd()
Application is ran as:
node my-project/server.js
There is no package.json at process.cwd()
. The application root directory will still be my-project because my-project/node_modules/app-root-dir/lib/index.js has node_modules in its path and the directory above node_modules is the application's root directory.
FAQs
Simple module to infer the root directory of the currently running node application
The npm package app-root-dir receives a total of 3,978,806 weekly downloads. As such, app-root-dir popularity was classified as popular.
We found that app-root-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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.