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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:09:34+00:00 2026-06-04T04:09:34+00:00

Can I build a module that exports instantiated variables? Module: var module1 = require(‘module1’)

  • 0

Can I build a module that exports instantiated variables?

Module:

var module1 = require('module1')
var Module2 = require('module2')

module1.dosomething(variables)
exports.module1 = module1

//or

module2 = new Modle2(variables)
module2.dosomething(variables)
exports.module2 = module2

Can I require the module above in many other files and use the exports as instantiated variables or will they be re-instantiated every time I require them and not shared between the files requiring them.

Thanks!

  • 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-04T04:09:36+00:00Added an answer on June 4, 2026 at 4:09 am

    Your example is confusing because you use module1 in multiple contexts, both as a module, a variable within another module, and an exported property of that module.

    Think of modules as closures and exports as return values. Most likely you want to export a function/factory function and call that every time if you want to create new instances with the export, anything else will be shared since it just returns the object.

    Module1

    module.exports.var1 = function(opts) {
        // do stuff
        return variables;
    };
    
    module.exports.var2 = new Blah(); // single instance
    

    Other module

    var var1 = require('module1').var1({ opt1: 'foo' }); // New instance every time
    var var2 = require('module1').var2; // Same var instance even if you include in another module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me build a module that displays articles under specific section only
I am trying to build a user-module that can be used in most of
Is there anyway I can build a Select statement that uses the Contains function?
I am trying to build a native client module that uses the improv lib
I'm trying to build a module that lets users with a certain role post
I am trying to build a very specific module that integrates Twitter bootstrap (for
I can build my project in Xcode(4.2) for debugging without issues, but when I
Is there a way I can build a bitmap strictly from RGB values for
Does anyone know if (and how) I can build an application (Java/Ruby/whatever) doing REST
I just found the IUI project on google code where you can build websites

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.