Fix My Tutorial
Report

Intercept HTTP Requests with Node.js nock

Open the original tutorial
Fixed Node.js 22 · checked 17 Oct 2026 · model cost $0.026

After applying the fix, the tutorial works again; the original code failed with a TypeError because nock 15.0.1 changed its export to an ES module, making the imported value an object rather than a function. The repair accesses the default export (or adjusts the import) to restore the expected function, resolving the error.

When it broke

Broke in nock 15.0.1, released 6 Oct 2026. nock 15.0.0 still runs this step, and 15.0.1 fails the same way. The tutorial was published in Aug 2015, so it worked for about 134 months.

1 change to make it work today

Write nock demo script

s3 · write_file migrate

Change the import to use the default export, which is the typical fix when a CommonJS require returns a module object instead of the function.

@@ -1,3 +1,3 @@
-var nock = require('nock');
+const nock = require('nock').default;
nock('https://davidwalsh.name')
@@ -37,6 +37,6 @@
.reply(function() {
- // Some logic
+// Some logic
- return [200, resultingContent];
+return [200, resultingContent];
});

Sources

  • Fix the 'is not a function' error in JavaScriptCommon causes are a library that did not load, an import that returned a module object instead of its function, or another script that replaced `$`. Fix how that value is loaded or referenced rather than hiding the error with a type check.

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error.

Badge

Add it to the tutorial so readers know when it was last checked.

Fix My Tutorial badge
Markdown
[![Fix My Tutorial](https://fix-my-tutorial.onrender.com/badge/ri-tw4nawKY.svg)](https://fix-my-tutorial.onrender.com/r/ri-tw4nawKY)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/ri-tw4nawKY"><img src="https://fix-my-tutorial.onrender.com/badge/ri-tw4nawKY.svg" alt="Fix My Tutorial"></a>