Illep
Illep

Reputation: 16851

Log statements in Node Module not getting printed

I am a new to Node JS. I have included a module via npm install '<module_name>. It was built correctly and there was no errors. Now, I wanted to debug it, so I placed a few console.log('some text') in code blocks of the module to see if the code by passes that line. Anyway, none of the log statements were displayed.

I am wondering if I have to compile or something the modules after adding the log staements. Am I missing something here.

Upvotes: 6

Views: 5384

Answers (2)

Mike K
Mike K

Reputation: 6491

For anyone coming here in the future, try console.error instead of console.log. For some decided reason or another, log was being overriding by the library I was monkey fixing. Took me way too long to find the culprit.

Upvotes: 1

lecstor
lecstor

Reputation: 5707

Your console.log statements are not being run, this could be caused by many things. Assuming you have added the console.log statements to the module code in the node_modules directory of your app..

  • does the module have src and dist directories and you have not edited the code that is actually being run? (this relates to needing to recompile, but editing the actual code that the module is running will be quicker and easier)
  • if this is in a server or long running script it will need to be restarted to load the changes
  • is this in a browser which might be caching the code (turn off browser cache)
  • is the code where you added the log statements actually being hit?

I would make sure I had a console.log statement in a part of the code guaranteed to be hit, just as a sanity check.

Upvotes: 5

Related Questions