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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:32:23+00:00 2026-06-12T23:32:23+00:00

I have an express project where I have a directory structure like so, my-app

  • 0

I have an express project where I have a directory structure like so,

  • my-app
    • routes
      • index.js
    • views
    • public
    • components
      • toolbar
    • test
      • components
      • toolbar

Now let’s say from my routes I want to require the component toolbar I do it like this

toolbar = require(__dirname + ‘/../components/toolbar’)

Now when I run my test for routes I need to require routes. When I do this I get an error at runtime that toolbar file could not be found.

Is there some global available like say __express_home that I could use in my require so that I would not run into this issue? I would then use it as so,

toolbar = require(__express_home + ‘/components/toolbar’)

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

    You can just do:

    toolbar = require('../components/toolbar')
    

    Here is an example from express’s github repo.

    var express = require('../..')
      , app = express()
      , site = require('./site')
      , post = require('./post')
      , user = require('./user');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I have setup a project in node with the express framework. I like that
I have two Express.js apps running on my server. A plain vanilla app called
I have a SQL2005 Express database that I would like to create a copy
I have a C# project that I have created in Visual Studio Express 2010.
I have an existing node express project and wanted to easily move it to
I am currently working on a project using the Express framework. I have a
I have a Visual C++ 2012 Express project on Git that uses an external
I have an express server that has a button that issues a POST which
I have 2 machines that have the Express version of C# on them. On

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.