# node-http-stub **Repository Path**: mirrors_jfromaniello/node-http-stub ## Basic Information - **Project Name**: node-http-stub - **Description**: Create an instance of http server that catches all requests to a given host. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2026-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Create an instance of http server that catches all requests to a given host. This is useful for tests. ## Install ``` npm i http-stub ``` ## Usage ```javascript var HttpStub = require('http-stub'); var stub = HttpStub('google.com'); stub.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World'); }).on('listening', function () { //it catchs all request to the given domain. request.get('https://google.com', function (err, resp, body) { assert.equal(body, 'Hello World'); }); }); ``` Mount an express application: ```javascript var HttpStub = require('http-stub'); var express = require('express'); var app = express(); app.get('/bo', function (req, res) { res.send('hello'); }); var stub = HttpStub('google.com'); stub.on('request', app); ``` ## License MIT 2015 - José F. Romaniello