Nodejs function for string containing function code

I am really very new to nodejs. Is there a way to convert the contents of a function to a string? Something like if I have:

function() { .... } 

I would like to have a function () {....} function. "

Is it possible?

+4
source share
1 answer

Functions already have a toString() method ... so just (function() {}).toString() should work.

For example, in node REPL:

 > (function() { console.log("hello"); }).toString() 'function () { console.log("hello"); }' 

Here is a link to some documentation .

+6
source

All Articles