You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

import-from

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-from

Import a module like with `require()` but from a given path


Version published
Weekly downloads
7.3M
decreased by-2.31%
Maintainers
1
Install size
5.82 kB
Created
Weekly downloads
 

Package description

What is import-from?

The npm package 'import-from' allows you to import modules from a specific path, bypassing the default behavior of Node.js module resolution. This can be particularly useful in scenarios where you need to dynamically choose different versions of a module or when working with plugins that may not be in the node_modules directory of the current project.

What are import-from's main functionalities?

Import module from a specific directory

This feature allows you to import a module by specifying the directory from which the module should be loaded. This is useful for loading modules dynamically based on runtime conditions or configurations.

const importFrom = require('import-from');
const specificModule = importFrom('/path/to/specific/directory', 'module-name');

Silent import attempt

This feature provides a way to attempt to import a module silently without throwing errors if the module does not exist. It is useful for optional dependencies that may or may not be present in a given environment.

const importFrom = require('import-from');
const tryImport = importFrom.silent('/path/to/directory', 'optional-module');

Other packages similar to import-from

Readme

Source

import-from

Import a module like with require() but from a given path

Install

$ npm install import-from

Usage

const importFrom = require('import-from');

// There is a file at `./foo/bar.js`

importFrom('foo', './bar');

API

importFrom(fromDirectory, moduleId)

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

importFrom.silent(fromDirectory, moduleId)

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

fromDirectory

Type: string

Directory to import from.

moduleId

Type: string

What you would use in require().

Tip

Create a partial using a bound function if you want to import from the same fromDir multiple times:

const importFromFoo = importFrom.bind(null, 'foo');

importFromFoo('./bar');
importFromFoo('./baz');
  • import-cwd - Import a module from the current working directory
  • resolve-from - Resolve the path of a module from a given path
  • resolve-cwd - Resolve the path of 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 modules lazily
  • import-global - Import a globally installed module

Keywords

FAQs

Package last updated on 01 Jun 2021

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc