Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Import a module like with `require()` but from the current working directory
The import-cwd npm package allows users to import modules using a path relative to the current working directory (CWD). This can be particularly useful when you want to require modules without having to worry about the relative path from the current file to the module, especially in complex project structures.
Import module from current working directory
This feature allows you to import a module using a path relative to the current working directory. It's similar to require(), but it resolves paths from the CWD instead of the current file's directory.
const importCwd = require('import-cwd');
const myModule = importCwd('./my-module');
Silent import with fallback
This feature attempts to import a module, but if it fails (e.g., the module does not exist), it will return a fallback value without throwing an error. This is useful for providing default configurations or modules.
const importCwd = require('import-cwd');
const myModule = importCwd.silent('./non-existent-module', 'default-module');
This package allows you to require modules from a string of code. It's similar to import-cwd in that it provides an alternative way to require modules, but it does not specifically relate to the current working directory.
import-fresh allows you to import a module by bypassing the cache, ensuring you get a fresh copy of the module. While it provides a different feature from import-cwd, it also offers an alternative way to require modules.
resolve-from is a package that resolves the path of a module from a given directory. It's similar to import-cwd in that it helps with module resolution, but it focuses on resolving paths rather than importing modules directly.
Import a module like with
require()
but from the current working directory
$ npm install import-cwd
const importCwd = require('import-cwd');
// Target module is at '/Users/sindresorhus/unicorn/foo.js'
console.log(__dirname);
//=> '/Users/sindresorhus/rainbow'
console.log(process.cwd());
//=> '/Users/sindresorhus/unicorn'
const foo = importCwd('./foo');
Like require()
, throws when the module can't be found.
Returns undefined
instead of throwing when the module can't be found.
Type: string
What you would use in require()
.
MIT © Sindre Sorhus
FAQs
Import a module like with `require()` but from the current working directory
The npm package import-cwd receives a total of 2,261,343 weekly downloads. As such, import-cwd popularity was classified as popular.
We found that import-cwd 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.