Module 3 Lesson 3: Power User Nodes
·Automation

Module 3 Lesson 3: Power User Nodes

Break the limits. Learn how to run shell commands on your server and write custom JavaScript functions directly inside n8n to handle complex data scenarios.

Module 3 Lesson 3: Power User Nodes

Sometimes, a "Drag and Drop" node isn't enough. You need the full power of a programming language. n8n provides two "Escape Hatches" for engineers: the Code Node and the Execute Command Node.

1. The Code Node (JavaScript/TypeScript)

This is the most powerful node in n8n. It allows you to write a custom function that receives the incoming data and returns a new set of data.

// Example: Converting "ounces" to "grams" for every incoming item
for (const item of $input.all()) {
  item.json.grams = item.json.ounces * 28.3495;
}
return $input.all();
  • Why use it?: Complex math, deep JSON manipulation, or integrating custom libraries.

2. The Execute Command Node (Bash/Shell)

This node runs a command directly on the terminal of your server (or inside your Docker container).

  • ls -la: List files in a folder.
  • ping google.com: Check connectivity.
  • python my_script.py: Trigger a local Python AI script.

3. Security Warning

These nodes are Dangerous.

  • If a hacker gains access to your n8n UI, they can run rm -rf / using the Execute Command node.
  • The Fix: n8n disables these by default in many cloud environments. In self-hosted mode, you must enable them with the environment variable N8N_BLOCK_ENV_VARS_IN_CODE=false.

4. Using External Libraries

You can "Inject" any NPM package into the Code Node.

  • Example: Use luxon for advanced date math.
  • Set the environment variable: NODE_FUNCTION_ALLOW_EXTERNAL=luxon.

Exercise: The Scripter's Test

  1. Add a Code node. Write a script that takes a field price and adds 20% tax to it.
  2. Add an Execute Command node. Run whoami. What user is n8n running as?
  3. Try to run python --version. Is Python installed in your n8n container?
  4. Why is it better to use a Code node for data processing instead of a chain of 10 Set nodes?
  5. Research: What is the "Function Item" node and how does it differ from the main "Code" node?

Summary

The Code and Execute Command nodes turn n8n from an "Automation tool" into an "Operating System." They allow you to bridge the gap between low-code ease and high-code flexibility.

Next Lesson: Managing the map: Managing Node Connections and Branching.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn