0

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 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I overlooked node.js file, which can be found only in original node src/node.js source - so after reading everything is clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.