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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:21:42+00:00 2026-06-05T09:21:42+00:00

What is the best way to separate all module dependencies into a new file

  • 0

What is the best way to separate all module dependencies into a new file called dependencies.js, and requiring that file in for example server.js. How do i return all these requires?

var express = require('express')
  , stylus = require('stylus')
  , fs = require('fs')
  , https = require('https')
  , app = express();
  • 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-05T09:21:43+00:00Added an answer on June 5, 2026 at 9:21 am

    You would need to assign them to the global object, so you shouldn’t do it at all

    global.express = require('express');
    global.stylus = require('stylus');
    global.fs = require('fs')
    global.https = require('https')
    global.app = global.express();
    

    There are actually a lot of reasons not to do this, but I’ll boil it down. First, you know that when declaring a variable in a module (e.g. var Foo = require('foo')), that variable is a part of the local scope of that module. global on the other hand is global to all of the modules. Think about the implications of all your modules sharing the same namespace for critical things which can not be guaranteed to be in any one state at a particular point in run-time (global is actually reset whenever node decides it needs to be!). This problem is potentially exacerbated if you ever begin using multiple processes (as @Hippo mentioned but did not explain).

    I can see why this would seem like a good idea at first, but the tiny amount of DRY you’d get from this technique pales in comparison to the unexpected failures you’d be hiding in your code.

    IMO, it’s much better to explicitly declare your dependencies in each module anyway. Sharing a list of deps across all modules would obfuscate the logical structure of your program.

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

Sidebar

Related Questions

If i have a int say 306. What is the best way to separate
What's the best way to have separate CSS for IE and other browsers? I'm
I wonder how is the best way to integrate Java modules developed as separate
the best way to explain is with example so: this is the model public
The best way I can think of to ask this is by example... In
The best way to store images into MySQL is by storing the image location
What's the best way in C# to set up a utility app that can
What is the best way to separate rendering code from the actually game engine/logic
In a large C++ solution, is there a best/standard way to separate the include
Some co-workers and I got into a debate on the best way to store

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.