Illustration by Stories by Freepik
ESniffer 🔬
Modern network analyze tool. Alternatives to Hoxy, Charles, etc.
Install
npm i esniffer
yarn add esniffer
Example
// index.js
import ESniffer from "esniffer";
import fs from "fs";
// Required if you want to monitor over HTTPS
const key = fs.readFileSync(`path/to/root-key.pem`);
const cert = fs.readFileSync(`path/to/root-cert.pem`);
const proxy = ESniffer.createServer({ secure: { key, cert } });
proxy.listen(8080);
proxy.on("request", (req) => {
req.pipe(process.stdout);
});
proxy.on("response", (res) => {
res.pipe(process.stdout);
});
proxy.on("info", (info) => {
console.log(info);
}
…Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. I'm a heavy user of Charles for debugging but sometimes struggle with its lack of customization.
If we can monitor HTTP/HTTPS traffic using Node.js script, we can do even more useful debugging and testing. So I've developed a simple module that allows for packet monitoring.
import ESniffer from "esniffer";
import fs from "fs";
// Required if you want to monitor over HTTPS
const key = fs.readFileSync(`path/to/root-key.pem`);
const cert = fs.readFileSync(`path/to/root-cert.pem`);
const proxy = ESniffer.createServer({ secure: { key, cert } });
proxy.listen(8080);
proxy.on("request", (req) => {
req.pipe(process.stdout);
});
proxy.on("response", (res) => {
res.pipe(process.stdout);
});
proxy.on("info", (info) => {
console.log(info);
});
proxy.on("error", (e) => {
console.error(e.message);
});
This is inheriting the EventEmitter
so we can access request
to the server and response
from the server via custom events. By installing and trusting a self-signed certificate, we can also monitor over HTTPS communication. See examples for more information.
Finally, I welcome bug reports and requests for additional features. Github Star, please!
ESniffer 🔬
Modern network analyze tool. Alternatives to Hoxy, Charles, etc.
Install
npm i esniffer
yarn add esniffer
Example
// index.js
import ESniffer from "esniffer";
import fs from "fs";
// Required if you want to monitor over HTTPS
const key = fs.readFileSync(`path/to/root-key.pem`);
const cert = fs.readFileSync(`path/to/root-cert.pem`);
const proxy = ESniffer.createServer({ secure: { key, cert } });
proxy.listen(8080);
proxy.on("request", (req) => {
req.pipe(process.stdout);
});
proxy.on("response", (res) => {
res.pipe(process.stdout);
});
proxy.on("info", (info) => {
console.log(info);
}
…
Top comments (0)