Socket
Socket
Sign inDemoInstall

resolve-dir

Package Overview
Dependencies
10
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    resolve-dir

Resolve a directory that is either local, global or in the user's home directory.


Version published
Weekly downloads
6.3M
decreased by-9.24%
Maintainers
1
Install size
78.5 kB
Created
Weekly downloads
 

Package description

What is resolve-dir?

The resolve-dir npm package is designed to resolve directory paths based on the given input. It can handle resolving home directory paths, relative paths, and paths based on the nearest package.json or node_modules directory. This makes it particularly useful in Node.js applications for file and directory path manipulations, especially when dealing with configurations or file loading where the exact path might vary depending on the environment or project structure.

What are resolve-dir's main functionalities?

Resolving home directory paths

This feature allows you to resolve the path to the user's home directory using the '~' symbol, which is commonly used in Unix-like systems to refer to the home directory.

const resolveDir = require('resolve-dir');
const homeDir = resolveDir('~');
console.log(homeDir);

Resolving relative paths

This feature enables the resolution of relative paths, making it easier to work with file paths that are relative to the current working directory or another specific directory.

const resolveDir = require('resolve-dir');
const relativePath = resolveDir('./relative/path/to/dir');
console.log(relativePath);

Resolving paths based on nearest package.json or node_modules

This functionality is useful for finding the path to a directory based on the location of the nearest package.json or node_modules directory. It's particularly handy in projects where you need to dynamically find the path to dependencies or project-related directories.

const resolveDir = require('resolve-dir');
const projectDir = resolveDir('node_modules/package-name');
console.log(projectDir);

Other packages similar to resolve-dir

Readme

Source

resolve-dir NPM version

Resolve a directory that is either local, global or in the user's home directory.

Install

Install with npm

$ npm i resolve-dir --save

Usage

var resolve = require('resolve-dir');

Returns a local directory path unchanged

resolve('a')
//=> 'a'

Resolves the path to user home

resolve('~')
//=> '/Users/jonschlinkert'
resolve('~/foo')
//=> '/Users/jonschlinkert/foo'

Resolves the path to global npm modules

resolve('@')
//=> '/usr/local/lib/node_modules'
resolve('@/foo')
//=> '/usr/local/lib/node_modules/foo'
  • expand-tilde: Bash-like tilde expansion for node.js. Expands a leading tilde in a file path to the… more | homepage
  • global-modules: The directory used by npm for globally installed npm modules. | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on September 21, 2015.

Keywords

FAQs

Last updated on 21 Sep 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc