🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

import-in-the-middle

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-in-the-middle

Intercept imports in Node.js

1.13.2
latest
Source
npm
Version published
Weekly downloads
14M
4.44%
Maintainers
2
Weekly downloads
 
Created

What is import-in-the-middle?

The 'import-in-the-middle' npm package allows developers to intercept and modify module imports in Node.js. This can be useful for debugging, logging, or altering the behavior of modules without modifying their source code.

What are import-in-the-middle's main functionalities?

Intercepting Module Imports

This feature allows you to intercept the import of specified modules ('fs' and 'path' in this case) and execute custom logic (logging in this example) whenever these modules are imported.

const { addHook } = require('import-in-the-middle');

addHook(['fs', 'path'], (exports, name, baseDir) => {
  console.log(`Module ${name} is being imported from ${baseDir}`);
  return exports;
});

const fs = require('fs');
const path = require('path');

Modifying Module Exports

This feature allows you to modify the exports of a module. In this example, a custom method is added to the 'fs' module.

const { addHook } = require('import-in-the-middle');

addHook(['fs'], (exports, name, baseDir) => {
  if (name === 'fs') {
    exports.customMethod = () => console.log('Custom method added to fs');
  }
  return exports;
});

const fs = require('fs');
fs.customMethod(); // Outputs: Custom method added to fs

Other packages similar to import-in-the-middle

Keywords

import

FAQs

Package last updated on 13 May 2025

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