Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:20:59+00:00 2026-05-18T23:20:59+00:00

When utilizing node.js’s newish support for –eval , I get an error ( ReferenceError:

  • 0

When utilizing node.js’s newish support for --eval, I get an error (ReferenceError: require is not defined) when I attempt to use require().

Here’s an example of the failure:

$ node --eval 'require("http");'

undefined:1

^
ReferenceError: require is not defined
    at eval at <anonymous> (node.js:762:36)
    at eval (native)
    at node.js:762:36
$

Here’s a working example of using require() typed into the REPL:

$ node
> require("http");
{ STATUS_CODES: 
   { '100': 'Continue'
   , '101': 'Switching Protocols'
   , '102': 'Processing'
   , '200': 'OK'
   , '201': 'Created'
   , '202': 'Accepted'
   , '203': 'Non-Authoritative Information'
   , '204': 'No Content'
   , '205': 'Reset Content'
   , '206': 'Partial Content'
   , '207': 'Multi-Status'
   , '300': 'Multiple Choices'
   , '301': 'Moved Permanently'
   , '302': 'Moved Temporarily'
   , '303': 'See Other'
   , '304': 'Not Modified'
   , '305': 'Use Proxy'
   , '307': 'Temporary Redirect'
   , '400': 'Bad Request'
   , '401': 'Unauthorized'
   , '402': 'Payment Required'
   , '403': 'Forbidden'
   , '404': 'Not Found'
   , '405': 'Method Not Allowed'
   , '406': 'Not Acceptable'
   , '407': 'Proxy Authentication Required'
   , '408': 'Request Time-out'
   , '409': 'Conflict'
   , '410': 'Gone'
   , '411': 'Length Required'
   , '412': 'Precondition Failed'
   , '413': 'Request Entity Too Large'
   , '414': 'Request-URI Too Large'
   , '415': 'Unsupported Media Type'
   , '416': 'Requested Range Not Satisfiable'
   , '417': 'Expectation Failed'
   , '418': 'I\'m a teapot'
   , '422': 'Unprocessable Entity'
   , '423': 'Locked'
   , '424': 'Failed Dependency'
   , '425': 'Unordered Collection'
   , '426': 'Upgrade Required'
   , '500': 'Internal Server Error'
   , '501': 'Not Implemented'
   , '502': 'Bad Gateway'
   , '503': 'Service Unavailable'
   , '504': 'Gateway Time-out'
   , '505': 'HTTP Version not supported'
   , '506': 'Variant Also Negotiates'
   , '507': 'Insufficient Storage'
   , '509': 'Bandwidth Limit Exceeded'
   , '510': 'Not Extended'
   }
, IncomingMessage: { [Function: IncomingMessage] super_: [Function: EventEmitter] }
, OutgoingMessage: { [Function: OutgoingMessage] super_: [Function: EventEmitter] }
, ServerResponse: { [Function: ServerResponse] super_: [Circular] }
, ClientRequest: { [Function: ClientRequest] super_: [Circular] }
, Server: 
   { [Function: Server]
     super_: { [Function: Server] super_: [Function: EventEmitter] } }
, createServer: [Function]
, Client: 
   { [Function: Client]
     super_: { [Function: Stream] super_: [Function: EventEmitter] } }
, createClient: [Function]
, cat: [Function]
}
> 

Is there a way to use require() with node’s --eval?

I’m on node 0.2.6 on Mac OS X 10.6.5.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:21:00+00:00Added an answer on May 18, 2026 at 11:21 pm

    No, at least not in 2.x.

    By looking at the source of 2.6:

    } else if (process._eval) {
      // -e, --eval
      var indirectEval= eval; // so the eval happens in global scope.
      if (process._eval) console.log(indirectEval(process._eval));
    

    It becomes clear that Node.js does not setup any of wrapper code for the eval’d code, therefore require etc. are not available.

    But this was changed in the 3.x version:

    } else if (process._eval) {
      // -e, --eval
      var rv = new module.Module()._compile('return eval(process._eval)', 'eval');
      console.log(rv);
    

    So in 3.x eval’d code works just like a regular module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error: SEVERE: Resource methods utilizing @FormParam and consuming multipart/form-data are no
I'm am utilizing a formset to enable users subscribe to multiple feeds. I require
On our new platform we are utilizing JSF. Our WebTrends tags are not reflecting
I'm utilizing LightOpenID and I'm trying to get attributes for this gmail authentication but
I'm new to node and am hacking together a node application utilizing node_pcap to
After utilizing the great trial and error for over an hour along with dozens
Imagine you are utilizing Parallelism in a multi-core system. Is it not completely possible
I've been utilizing the command pattern in my Flex projects, with asynchronous callback routes
We are utilizing the XML data type in Microsoft SQL Server 2005 for a
I'm utilizing the Reporting Services web service to generate a report and allow the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.