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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:06:48+00:00 2026-05-22T16:06:48+00:00

Looking at a random source file of the express framework for NodeJS , there

  • 0

Looking at a random source file of the express framework for NodeJS, there are two lines of the code that I do not understand (these lines of code are typical of almost all NodeJS files).

/**
 * Expose `Router` constructor.
 */

exports = module.exports = Router;

and

/**
 * Expose HTTP methods.
 */

var methods = exports.methods = require('./methods');

I understand that the first piece of code allows the rest of the functions in the file to be exposed to the NodeJS app, but I don’t understand exactly how it works, or what the code in the line means.

What do exports and module.exports actually mean?

I believe the 2nd piece of code allows the functions in the file to access methods, but again, how exactly does it do this.

Basically, what are these magic words: module and exports?

  • 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-05-22T16:06:49+00:00Added an answer on May 22, 2026 at 4:06 pm

    To be more specific:

    module is the global scope variable inside a file.

    So if you call require("foo") then :

    // foo.js
    console.log(this === module); // true
    

    It acts in the same way that window acts in the browser.

    There is also another global object called global which you can write and read from in any file you want, but that involves mutating global scope and this is EVIL

    exports is a variable that lives on module.exports. It’s basically what you export when a file is required.

    // foo.js
    module.exports = 42;
    
    // main.js
    console.log(require("foo") === 42); // true
    

    There is a minor problem with exports on it’s own. The _global scope context+ and module are not the same. (In the browser the global scope context and window are the same).

    // foo.js
    var exports = {}; // creates a new local variable called exports, and conflicts with
    
    // living on module.exports
    exports = {}; // does the same as above
    module.exports = {}; // just works because its the "correct" exports
    
    // bar.js
    exports.foo = 42; // this does not create a new exports variable so it just works
    

    Read more about exports

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

Sidebar

Related Questions

I am looking for a way to generate pseudo random number sequences that will
Kind of a random question... What I'm looking for is a way to express
I'm looking for some succinct, modern C# code to generate a random date between
I'm pretty sure that UIImagePNGRepresentation([UIImage imageWithCGImage:imageRef]) is the cause of random-looking memory leaks when
I'm looking for a random number that always generates the same random number for
I'm looking for a way to get a random database entry (Video) that has
I am looking for a random number generator in actionscript 3.0 that i can
I am looking for a pseudo random number generator which would be specialized to
I'm looking to generate a random number and issue it to a table in
I'm looking for tools for generating random but realistic text. I've implemented a Markov

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.