Socket
Socket
Sign inDemoInstall

resolve-from-npm

Package Overview
Dependencies
9
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    resolve-from-npm

Resolve the path of a module from the directory where npm is installed


Version published
Weekly downloads
789
increased by4.09%
Maintainers
1
Install size
84.1 kB
Created
Weekly downloads
 

Readme

Source

resolve-from-npm

npm version Build Status codecov

Resolve the path of a module from the directory where npm CLI is installed

const resolveFromNpm = require('resolve-from-npm');

require.resolve('node-fetch-npm');
//=> '/path/to/the/current/directory/node_modules/node-fetch-npm/src/index.js'

(async () => {
  await resolveFromNpm('node-fetch-npm');
  //=> '/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js'
})();

Installation

Use npm.

npm install resolve-from-npm

API

const resolveFromNpm = require('resolve-from-npm');

resolveFromNpm(moduleId)

moduleId: string (a module ID)
Return: Promise<string>

It resolves the path of a module from the path where npm-cli-dir resolves.

(async () => {
  await resolveFromNpm('./lib/install'); //=> '/usr/local/lib/node_modules/npm/lib/install.js'
})();

(async () => {
  try {
    // npm CLI doesn't contain a file './hi'
    await resolveFromNpm('./hi');
  } catch (err) {
    err.code; //=> 'MODULE_NOT_FOUND'
    err.message; //=> "Cannot find module './hi' from npm directory '/usr/local/lib/node_modules/npm'."
    err.npmDir; //=> '/usr/local/lib/node_modules/npm'
  }
})();

License

ISC License © 2017 - 2019 Watanabe Shinnosuke

Keywords

FAQs

Last updated on 11 Jun 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