Let's begin by starting our server:
$ node index.js
All good so far. Okay let's send a request to the server, we can navigate a browser to http://localhost:8080 or we can use curl (if installed) like so:
$ curl http://localhost:3000/
That should spit out some error HTML output containing a stack trace.
Even though an error has been thrown, the process hasn't crashed because express catches errors in routes to keep the server alive.
The terminal window that's running our server will also have a stack trace:
We can see (in this case) that the content function is calling itself recursively (but not too many times, otherwise there would be a Maximum call stack size exceeded error).
The content function looks like this:
function content (opts, c = 20) {
return --c ? content(opts, c) : opts.ohoh
}
The error message is Cannot read property 'ohoh' of undefined.
It should be fairly clear, that for whatever reason the opts argument is being input as undefined by a function calling the content function.
But because our stack is limited to 10 frames, we can't see what originally called the first iteration of the content function.
One way to address this is to use the --stack-trace-limit flag.
We can see that c defaults to 20, so if we set the limit to 21, maybe we'll see what originally called the c function:
$ node --stack-trace-limit=21 index.js
This should result in something like the following screenshot:
Now we can see that the original call is made from router.get in the routes.js file, line 6, column 12.
Line 6 is as follows:
res.send(content())
Ah... it looks like we're calling content without any inputs; of course, that means the arguments default to undefined.