Timestamp proces start and end

I want to log each process run, by setting a starting and ending timestamp.

At present I have two Function nodes, with code like this:

items[0].json.processStart = new Date();
return items;

which runs as the first node of the workflow, and:

items[0].json.processEnd = new Date();
return items;

which runs after all other nodes have completed.

These are then merged, and fires a set of nodes that use the json.processStart and json.processEnd values from the Merge node, to insert this into an auditing table in my PG database.

It works well, but I was wondering:

  • Is this the best approach?
  • Does n8n have the concept of global variables that I can use to set these values? Or, is using the output from Function nodes the only way?

The only other way would be to use the static workflow data as documented here:

Not sure however if that is a huge improvement.

Apart from that do you not have to merge the data of the two Function-Nodes. In the second Function-Node you can directly access the data of first one via $node as documented here:

That would make your workflow at least a little bit simpler.