Search code examples
javascriptnode.jsrequire

for what "../.." used for? I found it today in this line var express = require('../..');


Hey I was trying to understand node-js routes and found this sentence "var express = require('../..');" I don't understand the meaning/usage of '../..' here please can someone explain it to me?


Solution

  • '../..' is a relative path to index.js file which is situated two folders behind.

    Let's say hypothetically your folder structure looks like this -

    folder1
      - index.js
      - folder2
          - folder3
              - your-code.js
    

    and your-code.js looks like this,

    const express = require('../..');
    

    will mean to import the JS module from 'index.js' file in folder1