Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
[![NPM version](https://img.shields.io/npm/v/local-pkg?color=a1b858&label=)](https://www.npmjs.com/package/local-pkg)
The 'local-pkg' npm package is designed to help developers manage and interact with local packages in a Node.js environment. It provides utilities to check for the existence of local packages, resolve their paths, and require them conditionally.
Check if a local package exists
This feature allows you to check if a specific local package is installed. The function `isPackageExists` returns a boolean indicating the presence of the package.
const { isPackageExists } = require('local-pkg');
if (isPackageExists('some-local-package')) {
console.log('Package exists');
} else {
console.log('Package does not exist');
}
Resolve the path of a local package
This feature helps you resolve the absolute path of a local package. The function `resolvePackagePath` returns the path as a string.
const { resolvePackagePath } = require('local-pkg');
const packagePath = resolvePackagePath('some-local-package');
console.log(`Package path: ${packagePath}`);
Require a local package conditionally
This feature allows you to require a local package conditionally. The function `requireModule` attempts to require the package and returns it if successful, otherwise it returns `null`.
const { requireModule } = require('local-pkg');
const someLocalPackage = requireModule('some-local-package');
if (someLocalPackage) {
console.log('Package loaded successfully');
} else {
console.log('Failed to load package');
}
The 'resolve' package is a library for resolving module paths in Node.js. It provides similar functionality to 'local-pkg' in terms of resolving paths but does not include utilities for checking package existence or conditional requiring.
The 'pkg-up' package finds the closest package.json file by traversing up from a specified directory. While it helps in locating package.json files, it does not offer the same comprehensive utilities for managing local packages as 'local-pkg'.
The 'find-up' package is used to find a file or directory by walking up parent directories. It can be used to locate package.json files but lacks the specific package management utilities provided by 'local-pkg'.
Get information on local packages. Works on both CJS and ESM.
MIT License © 2021 Anthony Fu
FAQs
Get information on local packages.
The npm package local-pkg receives a total of 4,357,322 weekly downloads. As such, local-pkg popularity was classified as popular.
We found that local-pkg demonstrated a healthy version release cadence and project activity because the last version was released less than 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.