Export built-in libraries into `eval` context #4117

Closed
mmalecki opened this Issue Oct 11, 2012 · 7 comments

Comments

Projects
None yet
4 participants

For example:

[maciej@pc08 node (master)]$ ./node
> net
{ createServer: [Function],
  createConnection: [Function],
...

but

[maciej@pc08 node (master)]$ ./node -p 'net'

[eval]:1
net
^
ReferenceError: net is not defined
    at [eval]:1:1
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:454:26)
    at evalScript (node.js:380:25)
    at startup (node.js:77:7)
    at node.js:732:3

I think that we should export built-in libs into eval context too. Opinions?
If you guys think that this is a good idea, I'm willing to implement it.

/cc @isaacs

Actually, this modules are not automatically exported in REPL, this is only shortcut. Try this:

$ node
> console.log(net)
ReferenceError: net is not defined
    at repl:1:14
    ...

Personally I thing this is no needed, you can always use require()

Meh, -1 personally. -e/-p are implemented in the same way as evaling a script from stdin. I doubt we'd want that auto-load behavior when doing node < script.js.

Personally I don't like this shortcut in REPL, firstly i like it, but after a while I have name collision when I should inspect variable with same name as magic module loader.
May be this magic can be implemented better, as lazy property getters on global object.. (but in REPL only)

Thanks Nathan for reference

Owner

bnoordhuis commented Oct 12, 2012

-1 for pretty much the same reason as @TooTallNate.

Besides, it won't work for node -e 'net.createServer(...)', you would need to use node -e 'net; net.createServer(...)'.

Not much of a win compared to node -e 'require("net").createServer(...)'.

bnoordhuis closed this Oct 12, 2012

Owner

bnoordhuis commented Oct 12, 2012

(Technically speaking, node -e 'net.createServer(...)' could be made to work but that becomes too magical quick.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment