Skip to content

Instantly share code, notes, and snippets.

@sauravtom
Created July 13, 2020 19:54
Show Gist options
  • Save sauravtom/4c47e13102a3e1a5f5cc349092afe939 to your computer and use it in GitHub Desktop.
Save sauravtom/4c47e13102a3e1a5f5cc349092afe939 to your computer and use it in GitHub Desktop.

Revisions

  1. sauravtom created this gist Jul 13, 2020.
    59 changes: 59 additions & 0 deletions SauravCustomNode.node.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    import { IExecuteFunctions } from 'n8n-core';
    import {
    INodeExecutionData,,
    INodeType,
    INodeTypeDescription,
    } from 'n8n-workflow';


    import * as http from 'http'

    export class SauravCustomNode implements INodeType {
    description: INodeTypeDescription = {
    displayName: 'Saurav Custom Node',
    name: 'sauravCustomNode',
    group: ['transform'],
    version: 1,
    description: 'myCustomNode',
    defaults: {
    name: 'Saurav Custom Node',
    color: '#772244',
    },
    inputs: ['main'],
    outputs: ['main'],
    properties: [
    // Node properties which the user gets displayed and
    // can change on the node.
    {
    displayName: 'My String',
    name: 'myString',
    type: 'string',
    default: '',
    placeholder: 'Placeholder value',
    description: 'The description text',
    }
    ]
    };


    async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {

    const items = this.getInputData();

    let item: INodeExecutionData;
    let myString: string;

    // Itterates over all input items and add the key "myString" with the
    // value the parameter "myString" resolves to.
    // (This could be a different value for each item in case it contains an expression)
    for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
    myString = this.getNodeParameter('myString', itemIndex, '') as string;
    item = items[itemIndex];

    item.json['myString'] = myString;
    }

    return this.prepareOutputData(items);

    }
    }