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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:04:45+00:00 2026-06-13T04:04:45+00:00

Using Node.js, if I write app.js as: var commons = { title: ‘myTitle’, description:

  • 0

Using Node.js, if I write app.js as:

  var commons = {
    title: 'myTitle',
    description: 'MyDesc',
    menu: {
      home: {
        label: 'Home',
        url: '/',
      },
      contacts: {
        label: 'Contacts',
        url: '/contacts'
      }
    }
  }

  console.log(commons);

I’ve this output…

  {
    title: 'myTitle',
    description: 'MyDesc',
    menu: {
      home: {
        label : 'Home',
        url: '/'
      },
      contacts: {
        label: 'Contacts',
        url: '/contacts'
      }
    }
  }

…and it works fine.
But, if I would load a variable in app.js from another file (in the same path)…

commons.js:

exports.commons = {
    title: 'myTitle',
    description: 'MyDesc',
    menu: {
      home: {
        label: 'Home',
        url: '/',
      },
      contacts: {
        label: 'Contacts',
        url: '/contacts'
      }
    }
  }

app.js:

var commons = require('./commons');      
console.log(commons);

I’ve as output:

commons: {
        {
        title: 'myTitle',
        description: 'MyDesc',
        menu: {
            home: [Object],
            contacts: [Object]
        }
    }
 }

Why is this happening? How can I pass the variable across the two files correctly?

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

    In a module, exports is an object with all the things that are exported when the module is required somewhere else. So by setting exports.commons = { ... you are basically setting the commons property of the exports object. This means that you nested your actual object in another object for the export.

    In your other module, you import then the whole exports object using commons = require('./commons'). So your actual commons object that you set is at commons.commons.

    If you don’t want to nest the data in another object, you can just set the exports object directly, using module.exports:

    module.exports = {
        title: 'myTitle',
        description: 'MyDesc',
        ....
    }
    

    Then the import works as you expect it to.

    The [Object] in the output is, as pimvdb said, just something console.log does to not go too deep in the hierarchy. The data is still there, and you will probably see the contents just fine when you remove the first level as explained above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm successfully using Node.js + Express + Everyauth ( https://github.com/abelmartin/Express-And-Everyauth/blob/master/app.js ) to login to
I'm developing a webapp using Node.js and Express. Inside this app, I manage a
Using Express (for node.js ) How do I write a response after a callback?
I have the following Node.js code: var express = require('express'); var app = express.createServer(express.logger());
I am trying to write server side for my web application using Node.js. The
When using node.js to e.g. serve requests for a backbone.js front end, would node.js
I'm (almost) successfully using Node.js with Express and Redis to handle sessions. The problem
I'm inserting documents using node mongodb native driver into a mongodb (sic!). My objects
I am using Node.js (with Express.js) to pass a JSON data object from the
I'm interested in using Node.js as a socket server for stream-based communication with tens

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.