Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all the functions in my node js script?

I've tried looking at global, but it only contains variables, not functions. How can I list all the functions created in my script?

like image 568
Trindaz Avatar asked May 05 '12 19:05

Trindaz


2 Answers

If the function has a name, it'll show up in global just fine:

mb-work-laptop:~ markbessey$ node
> for (var k in global) { console.log(k); }
global
process
GLOBAL
root
Buffer
setTimeout
setInterval
clearTimeout
clearInterval
console
module
require
k
> function z(a) { return a*10; }
> for (var k in global) { console.log(k); }
global
process
GLOBAL
root
Buffer
setTimeout
setInterval
clearTimeout
clearInterval
console
module
require
k
z
> 
> global.z
[Function: z]
like image 27
Mark Bessey Avatar answered Sep 17 '22 23:09

Mark Bessey


Run node debug from command line with the file you want to look at. Then you can use list(some big number here)

node debug mini_file_server.js 
< debugger listening on port 5858
connecting... ok
debug> scripts
  26: mini_file_server.js
debug> list(1000)
  1 var http = require('http'),
  2     util = require('util'),
  3     fs   = require('fs');
  4 
  5 server = http.createServer(function(req, res){  
  6     var stream  = fs.createReadStream('one.html'),
  7         stream2 = fs.createReadStream('two.html');
  8     console.log(stream);
  9     console.log(stream2);
 10     stream.on('end', function(){
 11         stream2.pipe(res, { end:false});
 12     });
 13 
 14     stream2.on('end', function(){
 15         res.end("Thats all!");
 16     });
 17 
 18     res.writeHead(200, {'Content-Type' : 'text/plain'});
 19     stream.pipe(res, { end:false});
 20     stream2.pipe(res, { end:true});
 21 
 22 }).listen(8001);
 23 });
debug> 
like image 131
earlonrails Avatar answered Sep 18 '22 23:09

earlonrails