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

  • SEARCH
  • Home
  • 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 8453103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:40:56+00:00 2026-06-10T11:40:56+00:00

The argument of require(…) in node.js is a filename. If I had a module

  • 0

The argument of require(...) in node.js is a filename. If I had a module source code in a string code, could I somehow call require(code) and load functions from that string?

  • 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-06-10T11:40:57+00:00Added an answer on June 10, 2026 at 11:40 am

    A work around could be to write the module source code to a temporary file ./tmp-file.js and then require('./tmp-file'), and then remove the file.

    This is probably not optimal because you would either have to block and write the file synchronously, or put everything requiring that module in the callback to the async write.

    A working example for async file write (gist – also includes sync file write):

    var http = require('http');
    var fs = require('fs');
    
    var helloModuleString = "exports.world = function() { return 'Hello World\\n'; }";
    fs.writeFile('./hello.js', helloModuleString, function (err) {
      if (err) return console.log(err);
      var hello = require('./hello');
    
      http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end(hello.world());
      }).listen(1337, '127.0.0.1');
    
      console.log('Server running at http://127.0.0.1:1337/');
    });
    

    Results in:

    $ curl 127.0.0.1:1337
    > Hello World
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given code like this from a node.js neophyte like me: require('http').createServer(function( req, resp )
I have the following Node.js code: var express = require('express'); var app = express.createServer(express.logger());
Argument exception error is thrown at the following code. It's a simple code but
I had an argument with one of my friends who is an architect at
There are methods like these which require Class literals as argument. Collection<EmpInfo> emps =
I understand that execve() and family require the first argument of its argument array
In Qt, signals and slots require matching argument types: QObject::connect: Incompatible sender/receiver arguments QLabel::linkActivated(QString)
How do I require and check that an argument is a certain concept in
I just noticed that there's no version argument to R 's require() or library()
According to this post , requiring rubygems is an antipattern. require 'rubygems' The argument

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.