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 8934405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:46:55+00:00 2026-06-15T09:46:55+00:00

I have a problem in which i’m using a file to hold a list

  • 0

I have a problem in which i’m using a file to hold a list of modules and requiring this list in one call in my nodejs server. I want to use the modules in the list in a specific way.

modules.js –

Mods = {
  mymodule: require('./mymodule.js')
}

exports.f = function() {
  return Mods;
}

index.js –

f = require('./modules.js').f;

f().mymodule.echo("Hello World");

so instead of how i’m using f() now i want to put the name of the module i’m calling directly into the function so I can do things like this:

f = require('./modules.js').f;

f('mymodule').echo("Hello World");

I’ve tried a number of different experiments but can’t get it to work, is it possible to do this in javascript?

  • 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-15T09:46:56+00:00Added an answer on June 15, 2026 at 9:46 am

    Well, if you do this:

    var Mods = {
        mymodule: require('./mymodule.js');
    }
    
    module.exports = function( name ) {
        return Mods[name];
    };
    

    You can then do:

    var f = require( "./modules.js"); //no .f required
    
    f( "mymodule" ).echo( "Hello world");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem which requires solving for X in AX=B . A is
I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf
Im doing some javascript code and im using firefox. i have a problem which
I have this problem which made my scratch my head: Is there a way
I have a problem which appears when using Ubuntu Linux/Gnome, but seemingly not on
I have this problem which I really cannot understand. I am getting info from
I have special problem which I am trying to solve using CSS. My HTML
I have a problem which I can not solve. If this query is answered
I have this problem which i find a bit difficult to explain but I
Here I have a problem which I can't get over with. This is 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.