Socket
Book a DemoInstallSign in
Socket

@inspectr/express

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inspectr/express

Inspectr Express middleware to capture and inspect HTTP requests/responses with a built-in Inspectr UI.

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
0
Created
Source

Inspectr for Express

Inspectr is a NPM package that provides middleware for Express applications to capture and inspect every incoming request and outgoing response. It also includes a built‑in Inspectr UI (accessible at http://localhost:4004) where you can view request & response details in real time.

Request Inspectr Console Inspectr

Features

  • Express Middleware: Intercepts HTTP requests and responses and webhooks.
  • Real-time Inspector: Inspect Requests & Responses in the Inspectr App.
  • Log Requests: Log request data to the console.
  • Easy Integration: Simply add the middleware to your Express app.

Installation

Install the package via npm:

npm install @inspectr/express

Usage

  • Integrate the Inspectr Middleware into Your Express Application

In your Express application, require the package and use the middleware. For example:

// app.js
const express = require('express');
const inspectr = require('@inspectr/express');

const app = express();

// (Optional)Set the broadcast URL for Inspectr.
// inspectr.setBroadcastUrl('http://localhost:4004/sse');

// Add the inspectr middleware BEFORE your routes
app.use(inspectr.capture);

// Define your routes
app.get('/', (req, res) => {
 res.send('Hello, world!');
});

// Start your Express server as usual
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
 console.log(`Express app listening on port ${PORT}`);
});
  • Configuration Options

The capture() function accepts an optional configuration object to control how request and response data is handled:

OptionTypeDefaultDescription
broadcastbooleantrueIf true, sends request/response data to the SSE for real-time viewing in the Inspectr App.
printbooleantrueIf true, logs request/response details to the console in a structured format.

Examples Enable only console logging (disable SSE broadcasting):

app.use((req, res, next) => {
  inspectr.capture(req, res, next, { broadcast: false, print: true });
});

Enable only SSE broadcasting (disable console logging):

app.use((req, res, next) => {
  inspectr.capture(req, res, next, { broadcast: true, print: false });
});

Or access the data directly

// Add the inspectr middleware BEFORE your routes
app.use((req, res, next) => {
  inspectr(req, res, next, { broadcast: true, print: true })
    .then(data => {
      // Optionally, process the captured data (e.g., log it)
      console.log('Captured data:', data);
    })
    .catch(err => {
      console.error('Inspectr error:', err);
      next(err);
    });
});

Use default behavior (both enabled):

app.use(inspectr.capture);
  • Run the Inspectr App

The Inspectr App is provided as a separate command-line tool that serves the App on port 4004. Once your app is running ( and using the middleware), you can start the Inspectr App in another terminal:

If you installed the package locally:

  @inspectr/express

or as package.json script

"scripts": {
 "inspectr-app": "inspectr"
}

Then open your browser to http://localhost:4004 to view the inspectr interface.

Request Inspectr

Keywords

inspectr

FAQs

Package last updated on 18 Feb 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