I noticed that when running from repl, module and require properties of GLOBAL node object are present ( console.log(GLOBAL) ) But when I examine GLOBAL object from inside application (again with console.log ) there is no module and require property of GLOBAL object. I thought that node will actually create those properties when application is present ( for example HTTP server ) ,cause that is the situation when we need to require external module ? Can someone explain please ? Thank you
1 Answer
Every source file is wrapped into a function by node.js module helpers: see NativeModule.wrapper, NativeModule.wrap in node.js. In your source file exports, require, module, __filename, __dirname are arguments to that function.
When running repl, require and others are referenced from repl context - see REPLServer.prototype.createContext in repl.js
1 Comment
Miroslav Trninic
Thanks, I overlooked node.js file, which can be found only in original node src/node.js source - so after reading everything is clear.