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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:12:57+00:00 2026-06-07T23:12:57+00:00

Say that I have a server module called server.js and an api module called

  • 0

Say that I have a server module called server.js and an api module called api.js, server.js is the main module that i’m running.

Now, In the server, I have some functions that exports some data about the server,
In the api.js, I want to get some data from the server exported functions by adding: var api = require('./server.js');

The problem is that I get the server.js code running twice, first time when i’m running it, second when the api.js running the require('./server.js')

Any suggestions to bypass this issue?

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-07T23:12:58+00:00Added an answer on June 7, 2026 at 11:12 pm

    You should do it the other way around. Something like this:

    In server.js:

    api = require('./api.js');
    api.exportData({data1: foo, data2: bar});
    

    In api.js:

    var data1 = 'defaultvalue1', data2 = 'defaultvalue2';
    
    exports.exportData = function(dataObject) {
        data1 = dataObject.data1;
        data2 = dataObject.data2;
    };
    
    // rest of your code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have a data model called Widget . If I pick one
Let's say I have a stored procedure in Microsoft SQL Server 2005 that returns
Say that i have a generic dictionary with data like this (I hope the
Say that I have the following code: ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(myRunnable); Now, if
I know that I can have some HTTP request, say post , for some
Let's say that I have a bunch of class instances that serve different purposes,
Say that I have an immutable Point class with x and y parameters, and
Say that you have a loop and depending on the outcome of the loop
Say that I have an article with multiple pages. Each page has a short
Say that I have many blogs, and each blog has_many posts. These are stored

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.