{"id":47611,"library":"fetch-light-my-request","title":"fetch-light-my-request","description":"A lightweight wrapper that combines fetch-mock and light-my-request to allow Node.js fetch-based HTTP clients to be tested against plain HTTP or Fastify servers without real network calls. Version 0.1.4, early-stage package, requires Node >=20 and Fastify >=4 as a peer dependency. Ships TypeScript types. Differentiates by enabling fetch-mock's full mocking capabilities while using light-my-request's fast in-process request injection, allowing seamless testing of fetch-using code against Fastify or simple HTTP handlers.","status":"active","version":"0.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/segevfiner/fetch-light-my-request","tags":["javascript","nodejs","fetch","fetch-mock","light-my-request","http","injection","typescript"],"install":[{"cmd":"npm install fetch-light-my-request","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-light-my-request","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-light-my-request","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for creating mock from Fastify instance","package":"fastify","optional":true}],"imports":[{"note":"ESM-only package, named export. CommonJS require will fail.","wrong":"const createFetchMockLightMyRequest = require('fetch-light-my-request')","symbol":"createFetchMockLightMyRequest","correct":"import { createFetchMockLightMyRequest } from 'fetch-light-my-request'"},{"note":"Only works if fastify is installed; returns a FetchMock instance.","wrong":"","symbol":"createFetchMockLightMyRequestFromFastify","correct":"import { createFetchMockLightMyRequestFromFastify } from 'fetch-light-my-request'"},{"note":"Directly returns the fetch function, not FetchMock instance.","wrong":"","symbol":"createFetchLightMyRequest","correct":"import { createFetchLightMyRequest } from 'fetch-light-my-request'"}],"quickstart":{"code":"import { createFetchMockLightMyRequest } from 'fetch-light-my-request';\n\nconst fetchMock = createFetchMockLightMyRequest((req, res) => {\n  res.end('Hello, World!');\n});\n\nasync function main() {\n  const res = await fetchMock.fetchHandler('http://localhost/hello');\n  const text = await res.text();\n  console.log(text); // 'Hello, World!'\n}\nmain();","lang":"typescript","description":"Creates a fetch mock using a plain HTTP request handler, calls it, and logs the response body."},"warnings":[{"fix":"Use Node 20+ with ESM. Do not use require().","message":"Requires Node >=20, ESM-only. CommonJS not supported.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Use fastify 4.x. Monitor for updates.","message":"Fastify 5 is not yet supported; fastify peer dependency is >=4 and may not work with future versions.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Use fetchMock.fetchHandler directly, not global fetch(). To mock global fetch, you must reassign global.fetch = fetchMock.fetchHandler.","message":"fetchMock.fetchHandler mimics fetch but does not use global fetch; it is a standalone function.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use the signature (req, res) => { ... } where req is IncomingMessage and res is ServerResponse.","message":"The request handler (req, res) must be a plain Node.js HTTP request listener, not an Express or Koa middleware.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use createFetchMockLightMyRequest if you need to set up multiple URL patterns.","message":"When using createFetchLightMyRequest (not mock), the returned function does not have fetch-mock methods like mock() or restore().","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.1.4':41 '20':48 '4':51 'allow':20,82 'base':24 'call':39 'capabl':68 'client':26 'code':89 'combin':10 'depend':55 'differenti':59 'earli':43 'early-stag':42 'enabl':61 'fast':76 'fastifi':34,50,91 'fetch':2,12,23,63,87,98,100 'fetch-bas':22 'fetch-light-my-request':1 'fetch-mock':11,62,99 'fetch-us':86 'full':66 'handler':95 'http':25,32,94,106 'in-process':77 'inject':81,107 'javascript':96 'light':3,16,72,103 'light-my-request':15,71,102 'lightweight':7 'mock':13,64,67,101 'network':38 'node':47 'node.js':21 'nodej':97 'packag':45 'peer':54 'plain':31 'process':79 'real':37 'request':5,18,74,80,105 'requir':46 'seamless':83 'server':35 'ship':56 'simpl':93 'stage':44 'test':29,84 'type':58 'typescript':57,108 'use':70,88 'version':40 'without':36 'wrapper':8","created_at":"2026-06-07T16:52:24.607346+00:00","updated_at":"2026-06-07T16:52:24.607346+00:00","problems":[{"fix":"Use ES6 import statements or dynamic import(). Ensure project type is 'module' in package.json.","cause":"The package is ESM-only; CommonJS require() doesn't work.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported."},{"fix":"Verify import: import { createFetchMockLightMyRequest } from 'fetch-light-my-request'. Then call the factory function.","cause":"Import was done incorrectly or wrong symbol used.","error":"TypeError: fetchMock.fetchHandler is not a function"},{"fix":"Install fastify as a dev dependency, or use createFetchMockLightMyRequest with a plain handler.","cause":"Using createFetchMockLightMyRequestFromFastify without installing fastify.","error":"Error: Cannot find module 'fastify' ... Did you mean to set the 'fastify' peerDependency?"},{"fix":"Ensure handler signature is (req, res) and use res.end() to send response.","cause":"The request handler callback is not receiving proper Node.js response object.","error":"TypeError: res.end is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/segevfiner/fetch-light-my-request#readme","github":"https://github.com/segevfiner/fetch-light-my-request","docs":null,"changelog":null,"pypi":null,"npm":"fetch-light-my-request","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}