Available modules in node script

why do I get different results when trying to find out more about the http module in node.js in the following to ways?

  1. If I enter the node REPL and then print the content of the http module, i.e. if I run

    me@mymachine:~> node
    > console.log(http)

    I get all the details of the http object:

    { IncomingMessage: { [Function: IncomingMessage] super_: {
  2. If I write a script file called, say, script.js containing the following single line


    and execute it by running

    node script.js

    I get

    ReferenceError: http is not defined

I would have expected both cases to behave in the same way – either the http module is preloaded or not. Why is there a difference? What am I getting wrong here?

I thought I could ‘fix’ this by preloading module http by running (in version 2)

node -r http script.js

Shouldn’t this preload module http and thus avoid the reference error?

Looking forward to your input!