Obtaining the name of the current function being executed in Node.js

javascript, node.js

Solution

Short answer: `Object.values(this)[0].name`

Long Answer:

`let myInstanceArray = Object.values(this)` Enumerates the object properties as an array

`let myInstance = myInstanceArray[0]` Gets the first, and only, item in the array

`let myName = myInstance.name` Gets the name of the item.

Problem

In Node.js, I'm trying to obtain the name of current function being executed: ``` function doSomething(req, res) { console.log('Function name: ' + doSomething.name); } ``` This works well, but I'd like (if possible) to obtain the name within the current context. This way, if I renamed the method later I don't have change it manually. Is there a generic object (i.e. similar to 'this') that points to the current function being executed/current context? Thank you.

Original source

Related problems