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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:17:00+00:00 2026-06-05T01:17:00+00:00

I’m wondering if I’m structuring my nodejs app accordingly to account for best performance.

  • 0

I’m wondering if I’m structuring my nodejs app accordingly to account for best performance. My major concern is in regards to how I’m passing in moving my app reference around modules.

Basically in my app.js file I’m declaring all of my requires, libraries etc:

var app = {
    config     : require('../../config.json'),
    restify    : require('restify'),
    path       : require('path'),
    mongo      : require('mongodb'),
    model      : require('./models.js'),
    step       : require('step'),
    q          : require('q'),
    api        : require('./api_util.js'),
    underscore : require('underscore')
};

In my exports I’m passing in the entire app object. Now given my knowledge of JavaScript (you can correct me if I’m wrong), this will not create new instances of the object, it will simply pass in the object as a pointer and reference the same object in memory.

Now what I find myself doing aside from that (for ease) is in my restify library (the same can be done with Express), I’m appending the app value to the server request object like so:

app.server.pre(function (request, response, next) {
    request.app = app;
    return next();
});

Hence on every single request if I need quick access to any of my library declarations, config etc. I can easily access request.app. I don’t see this being an issue either, same logic the object acts a pointer back to the same memory space, so I’m not doubling memory usage or anything.

Is there a better/easier way of structuring this?

  • 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-05T01:17:02+00:00Added an answer on June 5, 2026 at 1:17 am

    You are correct about references being passed instead of objects being duplicated. From that point of view, you are not wasting extra space when passing references to your app.

    However, I would advise you against doing this: if you pass a reference to app around everywhere, what it tells me is that you don’t really know what you will need in this or that module.

    You should carefully plan your dependencies and know what each module will need so that you can pass the right dependencies for each module in your app.

    Regarding things like underscore or mongodb, you should not be doing what you are doing. You should only pass around modules that need initialization. For things like underscore or mongodb, node.js caches the definition the first time you require() it, so you can really call require at the top of every module that needs it.

    This will not incur any performance loss, and it will make it clearer what library each module requires.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.