NodeJs require('./file.js') issues

前端 未结 3 967
广开言路
广开言路 2021-02-02 05:16

I am having issues including files to execute in my NodeJs project.

I have two files in the same directory:

a.js

var test = \"He         


        
3条回答
  •  一整个雨季
    2021-02-02 05:36

    if you want to export the variable in another file.There are two patterns. One is a.js
    global.test = "Hello World"; //test here is global variable,but it will be polluted

    The other is
    a.js module.exports.test = "Hello World"; or exports.test= "Hello World"; b.js var test = require('./a.js'); //test in b.js can get the test in a.js console.log(test);

提交回复
热议问题