Reputation: 4632
I launch my script with:
node --inspect=1234 index.js
Then open Chrome dev tools Inspector and connect to it.
If I type console.log('hello')
it works and outputs message to console.
However if I type any function or variable contained in my script, it throws an error:
Uncaught ReferenceError: "my func / var" is not defined(…)(anonymous function) @ VM107:1
How to make it see and enable to interact with the contents of my script?
Upvotes: 1
Views: 1175
Reputation: 105459
Node.js treats every file as a CommonJS module. It means that everything you define in it is local to that module. When your run your script the function myFunc
in the index.js
is local to that module and is not available as a global object. Console works with global objects.
If you want to access the function from the console, you have to add it to the global object:
function f() {
console.log('f');
}
global.f = f;
Upvotes: 5