Building a custom node

I’m looking to build a custom node and integrate OAuth and eventually submit a PR to the main repo. I’ve been digging around the project and can’t figure out how to add a new node locally, I’ve created a node and imported the node to the /nodes-base/package.json file but whenever I run the API endpoints in /cli/Server.ts, the node doesn’t appear under the /node-types endpoint.

How can I get n8n to work with a custom module I build locally?

Did you see this guide already? If not I think it should explain everything you have to do:

Yes, I saw it. Thank you. I have followed the guide and created the node but it still does not appear? Any idea as to why this might happen? I’m running with npm run build from within /cli. Thank you.

Did you follow the full guide without taking any shortcuts? Because it, for example, mentions starting with npm run dev from the root folder. If you do only run npm run build in “/cli” it will never compile the TypeScript code to JavaScript and the node will so not be found on startup.

Hi Jan, I see the node in the /nodes-base/dist/credentials folder as a .js file. See attached screenshot. Is this correct? I’m still not getting the node to appear in the /node-types endpoint though…

Ah yes, that are two different things. There are credentials and there are the actual nodes (which contain all the logic and which use the credentials).
The credentials get returned from the credentials endpoint (/rest/credentials) and the nodes from the node-types one (/rest/node-types).

Understood. I created a custom credential and a custom node - both appear under the /nodes-base/dist/ folder (under /nodes-base/dist/nodes and /nodes-base/dist/ credentials, respectively). But in /rest/credentials and /rest/node-types and /rest/credential-types the custom nodes and credentials still don’t show…

Thoughts?

The only explanation I would have is still that one or multiple steps got skipped from the guide. Like for example the lerna-setup. Because then it would not link the module, it would use the npm installed one instead which would obviously not have your code and would so not show up.

I can’t get lerna to run without errors. See attached logs. I’m running from root, any thoughts?

[email protected] uninstall /Users/tjenkins/Desktop/n8n/node_modules/yorkie
node bin/uninstall.js

internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module ‘/Users/tjenkins/Desktop/n8n/node_modules/yorkie/bin/uninstall.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm WARN lifecycle [email protected]~uninstall: continuing anyway [email protected] uninstall: node bin/uninstall.js
npm WARN lifecycle Exit status 1
npm ERR! Maximum call stack size exceeded

Sorry, not the slightest idea. Are you running it directly on your host or inside of Docker? If Docker, what kind of image are you using? An Alpine one? If so maybe try with an Ubuntu based one.

As the issue is not directly related to n8n there is sadly not much I can help you with.

I’m running into the same issue and I think it’s because I’m a noob on n8n. I have followed every step up until the npm run dev and was unable to see my new node.

The only things different from the tutorial was my class:

export class Onfleet implements INodeType {
  description: INodeTypeDescription = {
      displayName: 'Onfleet',
      name: 'onfleet',
      icon: 'file:onfleet.png',
      group: ['transform'],
      version: 1,
      description: 'Onfleet API',
      defaults: {
          name: 'Onfleet',
          color: '#AA81F3',
      },
      inputs: ['main'],
      outputs: ['main'],
      credentials: [
      ],
      properties: [
          // Node properties which the user gets displayed and
          // can change on the node.
      ],
  };

Here’s what the packages/nodes-base/package.json looks like:

Any ideas why I couldn’t find my node?

Do you have the same file structure? Meaning the node it’s withim a folder called Onfleet.

Did you run the commands below? When you do, make sure you are in the root folder.

lerna bootstrap --hoist
npm run build
npm run dev

is it just not showing or is it showing you an error?

I believe so, you can check my forked repo for the file structure:

I ran the 3 steps all without errors under the n8n root folder, my node isn’t showing afterall.

It seems that is not an issue with the folder. When you run the 3 commands that I mentioned above what happens?

  1. Lerna runs correctly with just two warnings, successfully bootstrapped 6 packages
  2. npm run build compiles with two warnings, asset size limit and entrypoint size limit (both unrelated to my added node) - build completes
  3. npm run dev runs with some error (address already in use 0.0.0.0:5678) but everything else passes, app starts up with no type errors and no lint errors.

Cloned your branch, ran it locally and it works fine for me.

I think my problem was due to the fact that I had another n8n instance running. I’m going to kill it and rerun the 3 commands

Oh yeah I’m pretty sure it was because of my other running n8n instance, which resulted in the error message in the 3rd step. Thanks @RichardoE105 for double checking!

2 Likes