New Code Node: Basic Functions (Filter and Array)

I have a txt file with thousands of domain names (200k+, 3MB) and need to do a filter on it.

I could use SET + IF + List Nodes, but the process is really heavy, so I would like to make it all in a single Code Node.

As I’m not really familiar with the new process, would love to get your help.

Sample results I get from a HTTP call to a TXT file:

# file instructions
# find below the domains
cnn.com
bbc.co.uk
fox.com
99bugs.org
# end of list
  1. I need to .split the line breaks into array, so every domain will be a new item
  2. Filter only the lines not starting with # (keeping only the domain names)
  3. Get the final result with a clean domains list

I’m sure this should be a simple code but I can’t find many examples on how to use the new Code Function.

Thanks a lot!

I had to do something similar recently. Here are two ways you can do it, either from a field in an existing item, or from a binary:

3 Likes

What a legend! Worked like a charm.

The Code function displays a red warning asking to replace “if (line.match” to “if (line.json.match”, but it doesn’t work if I do that, I guess it’s a bug.

Thanks a lot, bud.

1 Like

Yeah the linter isn’t always right in the code node, you can safely ignore that one.

1 Like