I want to enable use of Http Get request inside the n8n custom script

Hi, lovely n8n community members. Hope you are doing well.
Recently I faced an issue while working on my custom training project.
I am using n8n-nodes-puppeteer community node and added workflow logic with custom script.
I need to send Http Get request to 2Captcha service for bypassing reCaptcha.
I installed node-fetch npm module and enabled that module as external, so in normal custom code script, I can access node-fetch module. But in n8n-nodes-puppeteer custom script, I cannot import.
It shows me an error that cannot find the module node-fetch.
I also tried to use XMLHttpRequest which is JavaScript builtin feature, but it doesn’t work too. In the custom script, it doesn’t recognize XMLHttpRequest object.
Please let me know a way if you already faced similar issue before. Thanks.

n8n uses Axios for http requests. You might want to try that instead of adding alternatives like node-fetch. This older post about using axios in a code node says you should be able to do it after you add the environment variable to allow it (which I just verified works in version 1.84.3):

NODE_FUNCTION_ALLOW_EXTERNAL=axios

Here’s a starting point for the code.

var request = require('axios')

const response = await request({
    method: "get",
    url: "https://httpbin.org/get",
});

return [{"replaceme": "with data from response" }];

Thanks for your reply. In normal code node, node-fetch module is also working well. I allowed node-fetch as external, and I can access the module in code script.
But if I open the custom script editor from n8n-nodes-puppeteer It says ‘cannot find the module node-fetch’.
So it’s the problem. Let me know if you had faced this sort of issue before or any upcoming suggestions would be appreciated. Thanks

Thanks for making it clearer that your issue really isn’t with the n8n core functionality but with an independently developed custom/community node. I sorta missed that before.

That might be the distinction that makes the difference here though.

  • The NODE_FUNCTION_ALLOW_EXTERNAL environment variable in n8n modifies the sandbox environment where n8n’s core Code node runs JS or Python code, so there’s probably no expectation that it would change the environment for the custom node you are using.
  • Any dependencies needed by a custom node should be included in the custom node’s code directory (node_modules subdirectory).

@hubschrauber I installed node-fetch module inside node module directory (.n8n/nodes/n8n-nodes-puppeteer). But still cannot find node-fetch module in the custom script. Could you let me know how to resolve it?