How can I pass a variable while using `require` in node.js?

前端 未结 4 1473
生来不讨喜
生来不讨喜 2020-12-13 13:54

In my app.js I have below 3 lines.

var database = require(\'./database.js\');
var client = database.client
var user = require(\'./user.js\')         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 14:23

    Why do you use require, for scr, no prom use source. It's the same as require and we can pass args in this fuction.

    var x="hello i am you";
    console.log(require(x));  //error
    console.log(source(x));   //it will run without error
    

提交回复
热议问题