NodeJS中的PHP auto_prepend_file替代方案

时间:2016-10-17 09:38:51

标签: node.js

在我的NodeJS环境中,我想要包含一个包含一些个人帮助函数的文件。

基本上我想要与PHP auto_prepend_file

相同的行为

它应该自动包含在项目和NodeJS CLI中。理想情况下,它不应该需要require语句。它应该只为每个地方都可用的函数创建一些全局变量。

1 个答案:

答案 0 :(得分:0)

我不确定我理解你......但你的意思是include还是require_once

可以这样使用:

require_once('/path/to/file/helper_functions.php');

include('/path/to/file/helper_functions.php');

一个例子可以是:

$funcs_path = '/path/to/file/helper_functions.php'
if(file_exists ($funcs_path))
{
  require_once($funcs_path);
}

我希望这可以帮到你