简体   繁体   English

如何访问\需要另一个文件夹中的 js 文件

[英]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在我的 test.js 中,我需要 common.js 文件,所以我使用它

var test = require("...../config/common.js"), it shows "can't find the module Cannot find module '...../config/common.js" var test = require("...../config/common.js"),它显示“找不到模块找不到模块'...../config/common.js”

Any suggestions?有什么建议么?

should be:应该:

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

with normal rquire using express使用快递的正常要求

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

or with es6 you can do it like this way或者使用 es6 你可以这样做

import test from ("../../../config/common.js")从 ("../../../config/common.js") 导入测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM