Socket
Socket
Sign inDemoInstall

import-in-the-middle

Package Overview
Dependencies
Maintainers
2
Versions
33
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


Version published
Weekly downloads
10M
increased by4.99%
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

FAQs

Package last updated on 30 Jul 2024

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc