Socket
Socket
Sign inDemoInstall

resolve-cwd

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

resolve-cwd

Resolve the path of a module like `require.resolve()` but from the current working directory


Version published
Maintainers
1
Weekly downloads
24,237,762
decreased by-6.93%

Weekly downloads

Package description

What is resolve-cwd?

The resolve-cwd npm package is a utility that allows you to resolve the path of a module or file based on the current working directory (CWD). This can be particularly useful in scenarios where you need to require modules dynamically based on the execution context or when working with tools that change the current working directory.

What are resolve-cwd's main functionalities?

Resolve module path from CWD

This feature allows you to resolve the path of a module from the current working directory. It's useful when you need to require a module dynamically and the module's location is relative to where the script is being executed.

const resolveCwd = require('resolve-cwd');
const modulePath = resolveCwd('some-module');
console.log(modulePath);

Silent failure on non-existent module

This feature provides a way to attempt to resolve a module's path without throwing an error if the module does not exist. It's useful for cases where you want to check for a module's presence and handle the absence gracefully.

const resolveCwd = require('resolve-cwd');
const modulePath = resolveCwd.silent('non-existent-module');
if (modulePath) {
  console.log('Module found at:', modulePath);
} else {
  console.log('Module not found');
}

Other packages similar to resolve-cwd

Readme

Source

resolve-cwd Build Status

Resolve the path of a module like require.resolve() but from the current working directory

Install

$ npm install resolve-cwd

Usage

const resolveCwd = require('resolve-cwd');

console.log(__dirname);
//=> '/Users/sindresorhus/rainbow'

console.log(process.cwd());
//=> '/Users/sindresorhus/unicorn'

console.log(resolveCwd('./foo'));
//=> '/Users/sindresorhus/unicorn/foo.js'

API

resolveCwd(moduleId)

Like require(), throws when the module can't be found.

resolveCwd.silent(moduleId)

Returns undefined instead of throwing when the module can't be found.

moduleId

Type: string

What you would use in require().

  • resolve-from - Resolve the path of a module from a given path
  • import-from - Import a module from a given path
  • import-cwd - Import a module from the current working directory
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • import-lazy - Import a module lazily
  • resolve-global - Resolve the path of a globally installed module

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 30 Apr 2019

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