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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:54:08+00:00 2026-06-12T04:54:08+00:00

Simple example: file1 module.exports.foo = function(obj) { module.exports.obj = obj; } file2 file1 =

  • 0

Simple example:

file1

module.exports.foo = function(obj) {
  module.exports.obj = obj;
}

file2

file1 = require("file1")
var something = {a: "a"};
file1.foo(something); //export "something" being a part of file2

The example above is not working.

What I want is basically a module.exports helper, since I plan a few helpers for whole object “exportion”.

Thank you

  • 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-12T04:54:10+00:00Added an answer on June 12, 2026 at 4:54 am

    module in file1.js is a different instance from that in file2.js.

    file1.js

    module.exports.foo = function(obj) {
        module.exports.obj = obj; 
        return module;
    }  
    

    file2.js

    console.log("running file2");
    
    file1 = require("./file1");
    
    var something = {a: "a"}; 
    var moduleOfFile1 = file1.foo(something); //export "something" being a part of file2 
    
    console.log("file1 module: " + moduleOfFile1.id);
    console.log("file2 module: " + module.id);
    

    console:

    node file2.js
    

    id returned are different


    Update

    alternatively, why not update file2.js to extend its module.exports

    File2.js

    // well, you may copy `extend` implementation if you 
    // do not want to depend on `underscore.js`
    var _ = require("underscore");     
    file1 = require("./file1");  
    
    _.extend(module.exports, file1);
    
    var something = {a: "a"};  
    // or do something else
    
    _.extend(module.exports, {
        obj: something
    });
    

    File3.js

    file2 = require("./file2.js");
    console.log(file2.obj.a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A simple example: Let's say I have one alias being sourced somewhere as: alias
A simple example of what I'd like to achieve: <body> <div style=float:left;> Hey, look
This simple example fails to compile in VS2K8: io_service io2; shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20))); As
Very simple example: #include <string> #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int argc,
Very simple example - hoping for a simple solution: char x[7]; if(fgets(x,5,stdin)) printf(y); else
so I have a simple example--a fully crossed three treatment three context experiment, where
I've created a simple example to show what I'm having problems with. Place a
In this simple example, i want to create a String array populated with each
I'm creating simple example on JSF. It's small Login application. My problem is duplicate
I am looking for simple example code for setting up a Message in an

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.