I have a simple web scraping workflow using node js in a code node.
I am using the following modules:
const got = require(“got”);
const deasync = require(‘deasync’); // Re-added
const cheerio = require(‘cheerio’);
const TurndownService = require(‘turndown’);
I am on latest version and every time I run the worflow my containers cpu usages drop to 0 and it becomes unresponsiv but still runing.
Logs do not show anything but when I check on the excecution after the restart it says maybe out of memory but on the monitoring it din not show up even close to the set 4gb ram limit
This is a common issue when using require() inside the Code node — especially in self-hosted or containerized environments.
A few things to clarify:
The Code node runs in a sandbox
n8n’s Code node does not support native require() of external packages unless:
You’re self-hosting with NODE_FUNCTION_ALLOW_EXTERNAL set, and
Those modules are installed inside the Docker container
But even with that setup, importing large modules or ones that do async I/O (like got or deasync) inside the Code node can lead to memory leaks or hanging executions — because the sandboxed execution environment wasn’t built to handle that level of complexity.
Best Practice: Avoid external HTTP or DOM manipulation packages inside the Code node
Instead:
Use the built-in HTTP Request node for fetching pages
Use the HTML Extract node (or Function node with cheerio preprocessed)
Move scraping logic to an external microservice (e.g., small Express app) and call it from n8n
If you really need Node.js libraries, consider switching to:
An Execute Command node running a script
Or run the logic in a [custom webhook + external scraper combo]
Lastly, I recommend checking:
Whether your require() is importing from the right path inside Docker
That your memory doesn’t spike during unresolved promises — e.g., deasync can lock the thread if not handled carefully
Let me know if you want a working alternative setup using Function + HTTP + cheerio outside the Code node.