unknown
unknown

Reputation: 689

How to access\require a js file from another folder

I have a directory structure,

 --- root
  |--- server
     |--- lib
        |--- core
           |--- Test.js
           |--- Test2.js
  |---config 
          |--- Common.js 

in my test.js I require common.js files so I use this

var test = require("...../config/common.js"), it shows "can't find the module Cannot find module ' ...../config/common.js"

Any suggestions?

Upvotes: 0

Views: 580

Answers (2)

shubham yadav
shubham yadav

Reputation: 172

with normal rquire using express

var test = require("../../../config/common.js")

or with es6 you can do it like this way

import test from ("../../../config/common.js")

Upvotes: 1

Karl L
Karl L

Reputation: 1725

should be:

var test = require("../../../config/common.js")

Upvotes: 3

Related Questions