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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:59:08+00:00 2026-06-12T07:59:08+00:00

What modules does node.js look for when it encounters var foo=require(../) ? It would

  • 0

What modules does node.js look for when it encounters var foo=require(../) ?

It would seem that it would look in the directory one UP from the current one, but what exactly would it look for and do?

Perhaps there is an analogy with include in C or import in Python?

I’ve been starting with node.js and reading
http://nodejs.org/api/modules.html
and came upon example code on github such as

var express = require('express')
  , tracker = require('../')

This code would seem to assign variable express contents of express module (file) whose path must be global after using npm to install express, that much seems understandable,although I understand there are two types of module installation, but that is another question.

But what contents are assigned to variable tracker?

  • 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-12T07:59:10+00:00Added an answer on June 12, 2026 at 7:59 am

    This depends on WHAT is in that directory.

    If X begins with ‘./’ or ‘/’ or ‘../’:

    a. LOAD_AS_FILE(Y + X)
    b. LOAD_AS_DIRECTORY(Y + X)

    LOAD_AS_FILE(X):

    1. If X is a file, load X as JavaScript text. STOP
    2. If X.js is a file, load X.js as JavaScript text. STOP
    3. If X.node is a file, load X.node as binary addon. STOP

    LOAD_AS_DIRECTORY(X):

    1. If X/package.json is a file,
      a. Parse X/package.json, and look for "main" field.
      b. let M = X + (json main field)
      c. LOAD_AS_FILE(M)
    2. If X/index.js is a file, load X/index.js as JavaScript text. STOP
    3. If X/index.node is a file, load X/index.node as binary addon. STOP
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does information hiding help to decouple the modules that comprise a system?
I have a node app that has a string of require s, like this:
I'm using the jsdom node.js module for an app that does some web scraping
What would be the preferred way to handle internal modules within a node.js application?
Does the CCK api allow me to create a node type, from a custom
Does Node.JS support sending binary data? or does it require a Base64 layer? Also,
As I just found out import package does not make the package's modules available
Does somebody know a module, which has a function that returns ( for example
Does anyone know if Python's shelve module uses memory-mapped IO? Maybe that question is
Preface: Yes, I've read: http://drupal.org/node/547518 I am writing 'foo' module for Drupal6, where I

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.