ThisCalculator

Everyday

How to Build & Install a Custom n8n Node

Updated · Standard formula, shown below

This guide walks you through creating a custom node for n8n, the workflow automation tool, and installing it on your self-hosted server. You’ll learn how to set up the development environment, write a simple node, package it, and make it available in your n8n instance. By the end, you’ll be able to extend n8n with your own integrations.

What You’ll Need

  • A self-hosted n8n installation (Docker, npm, or PM2) with admin access.
  • Node.js (version 18 or later) and npm installed on your development machine.
  • Basic familiarity with JavaScript/TypeScript and n8n’s node structure.
  • A text editor or IDE (e.g., VS Code).
  • Optional: Git for version control.

Step-by-Step

  1. Set up the n8n community node development environment. The official way is to use the n8n-node-dev CLI. Install it globally: npm install -g n8n-node-dev. This tool scaffolds a new node package and helps with building.
  2. Create a new node package. In your working directory, run n8n-node-dev new. Follow the prompts to name your node (e.g., my-custom-node) and choose the node type (e.g., “Action”). This creates a folder with the basic structure: package.json, tsconfig.json, and a src directory.
  3. Understand the generated structure. Inside src, you’ll find a .node.ts file (the main node definition) and a .node.json file (descriptions for UI). For a simple node, you can combine them in a single TypeScript file.
  4. Write your custom node logic. Open the generated .node.ts file. You’ll see a class that extends INodeType. Implement the execute method where you define what the node does. For example, a node that returns the current time:
    import { IExecuteFunctions } from 'n8n-core';
    import { INodeTypeDescription, INodeType } from 'n8n-workflow';
    
    export class MyCustomNode implements INodeType {
      description: INodeTypeDescription = {
        displayName: 'My Custom Node',
        name: 'myCustomNode',
        group: ['transform'],
        version: 1,
        description: 'Returns the current time',
        defaults: { name: 'My Custom Node' },
        inputs: ['main'],
        outputs: ['main'],
        properties: [
          {
            displayName: 'Format',
            name: 'format',
            type: 'options',
            options: [
              { name: 'ISO', value: 'iso' },
              { name: 'Unix', value: 'unix' },
            ],
            default: 'iso',
          },
        ],
      };
    
      async execute(this: IExecuteFunctions) {
        const format = this.getNodeParameter('format', 0) as string;
        const now = new Date();
        const result = format === 'iso' ? now.toISOString() : Math.floor(now.getTime() / 1000).toString();
        return this.helpers.returnJsonArray({ timestamp: result });
      }
    }
    
  5. Update the package.json. Ensure the main field points to the built file (e.g., dist/index.js). Add a n8n field to specify the node name:
    "n8n": {
      "n8nNodesApiVersion": 1,
      "nodes": ["dist/MyCustomNode.node.js"]
    }
  6. Build the node. Run npm run build (or n8n-node-dev build if you have a separate build script). This compiles TypeScript to JavaScript in the dist folder.
  7. Test locally (optional but recommended). Use n8n-node-dev test to run a basic test that loads the node and checks for errors. You can also run n8n locally with n8n start and install the node via npm link for quick testing.
  8. Install the node on your self-hosted server. The method depends on how you run n8n:
    • Docker: Copy the built package into the container. The simplest way is to mount a volume: -v /path/to/your/node:/usr/local/lib/node_modules/n8n/node_modules/my-custom-node. Then restart the container. Alternatively, build a custom Docker image that includes your node.
    • npm/PM2: If you installed n8n globally, install your node globally too: npm install -g /path/to/your/node. Then restart n8n.
    • Using n8n’s community node feature: If your node is published to npm, you can install it directly in the n8n UI under “Settings > Community Nodes”. For self-hosted, you can also set the N8N_COMMUNITY_NODES environment variable to include your package name.
  9. Restart n8n. After installing, restart the n8n service to load the new node. Check the logs for any errors.
  10. Verify the node appears. In the n8n editor, search for your node by its display name. Drag it onto the canvas and test it with a simple workflow.

Common Mistakes

  • Forgetting to build – Installing the TypeScript source directly won’t work; n8n expects compiled JavaScript.
  • Incorrect path in package.json – The main field must point to the actual built file, and the n8n.nodes array must list the correct filenames.
  • Not matching n8n’s API version – If your node uses an older API version, it may not load. Check the n8n documentation for the current version.
  • Missing required properties – The node description must include inputs, outputs, defaults, and properties; otherwise, n8n may reject it.
  • Using relative paths in Docker – When mounting a volume, use absolute paths to avoid confusion.

Tips

  • Use the n8n-node-dev CLI for scaffolding – It ensures you start with the correct structure and avoids manual errors.
  • Test with a simple node first – Get a minimal node working before adding complex logic.
  • Keep your node package small – Only include necessary dependencies to avoid conflicts with n8n’s own modules.
  • Check n8n’s community node examples – They provide real-world patterns for handling credentials, webhooks, and more.
  • Use versioning – If you update your node, increment the version and test thoroughly before deploying.

Troubleshooting

  • Node not appearing in the editor – Check the n8n logs for errors like “Failed to load node”. Verify that the built file exists and the path in package.json is correct. Also ensure the node name is unique and doesn’t conflict with existing nodes.
  • Error: “Cannot find module” – This usually means the node’s dependencies aren’t installed. Run npm install in the node’s directory before building. For Docker, make sure the volume mount includes the node_modules folder or run npm install inside the container.
  • Node loads but throws an error during execution – Check the error message in the workflow execution. Common issues include incorrect parameter names or missing imports. Use console.log statements and run n8n with N8N_LOG_LEVEL=debug for more details.
  • Changes not taking effect – After modifying the node, you must rebuild it and restart n8n. Clear the browser cache if the node still shows old behavior.
  • Docker container doesn’t see the node – Verify the volume mount is correct and the container has read access. You can exec into the container and check if the node files are present.

Frequently Asked Questions

Can I write a custom node in plain JavaScript instead of TypeScript?

Yes, but n8n’s official tooling and examples are TypeScript-based. You can write JavaScript, but you’ll need to adjust the build process and ensure the structure matches what n8n expects.

How do I add credentials to my custom node?

You define a credentials property in the node description, and then in the execute method use this.getCredentials('yourCredentialName'). You also need to create a credential class that extends ICredentialType.

Can I install a custom node without rebuilding the whole n8n image?

Yes, using Docker volumes or the community nodes feature. For npm installs, you can install the package globally and restart n8n.

Is there a way to test my node without a full n8n installation?

You can use n8n-node-dev test to run basic checks. For integration testing, you can run n8n locally with a temporary database and install the node via npm link.

How do I update an existing custom node?

Modify the source, rebuild, and reinstall. If you’re using Docker, rebuild the image or update the volume mount. For npm, reinstall the package and restart n8n. Make sure to increment the version in package.json.

What if my node needs to make HTTP requests to an external API?

You can use the built-in this.helpers.httpRequest method. It handles authentication and returns a promise. Refer to n8n’s documentation for detailed examples.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.