
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
is-resolvable
Advanced tools
The is-resolvable npm package is a utility that checks if a module ID (a string) can be resolved to a valid module using Node.js' resolution algorithm. This can be useful for determining if a module is available for use without actually requiring it.
Check if a module is resolvable
This feature allows you to check if a given module ID can be resolved to a valid module. It returns true if the module can be resolved and false otherwise.
const isResolvable = require('is-resolvable');
console.log(isResolvable('express')); // true if 'express' is installed
console.log(isResolvable('./local-module')); // true if './local-module' exists
The resolve package provides a synchronous and asynchronous method to resolve a module path as Node.js does. It offers more detailed control over the resolution process compared to is-resolvable, including custom module directories and file extensions.
The require-resolve package is similar to is-resolvable but also provides the full path to the resolved module. It can be used to check if a module is resolvable and to get the path to the module if it is.
The module-exists package checks if a module exists and can be required. It is similar to is-resolvable but focuses on the existence check rather than the resolution process.
A Node.js module to check if a given module ID is resolvable with require()
const isResolvable = require('is-resolvable');
isResolvable('fs'); //=> true
isResolvable('path'); //=> true
// When ./index.js exists
isResolvable('./index.js') //=> true
isResolvable('./index') //=> true
isResolvable('.') //=> true
npm install is-resolvable
const isResolvable = require('is-resolvable');
moduleId: string
(module ID)
options: Object
(require.resolve
options)
Return: boolean
It returns true
if require()
can load a file form a given module ID, otherwise false
.
const isResolvable = require('is-resolvable');
// When ./foo.json exists
isResolvable('./foo.json'); //=> true
isResolvable('./foo'); //=> true
isResolvable('./foo.js'); //=> false
// When `eslint` module is installed but `jshint` isn't
isResolvable('eslint'); //=> true
isResolvable('jshint'); //=> false
// When `lodash` module is installed
isResolvable('lodash/isObject'); //=> true
isResolvable('lodash/fp/reject.js'); //=> true
The second argument accepts an options object for require.resolve()
.
// When ./bar/baz.js exists
isResolvable('./baz.js'); //=> false
isResolvable('./baz.js', {paths: ['bar']}); //=> true
ISC License © 2018 Shinnosuke Watanabe
FAQs
Check if a module ID is resolvable with require()
The npm package is-resolvable receives a total of 5,491,011 weekly downloads. As such, is-resolvable popularity was classified as popular.
We found that is-resolvable 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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.