gpt4 book ai didi

javascript - Node.js 从模块内部获取模块的文件名?

转载 作者:行者123 更新时间:2023-11-30 12:55:32 24 4
gpt4 key购买 nike

如何在加载期间从模块本身内部获取 Node.js 模块的名称?

//mymodule.js
console.log(GET_MODULE_FULL_PATH_NAME())

//prog.js

require('/full/path/module')
OR
require('./module')
OR
require('module.js')

最佳答案

使用__文件名。这会让你得到你想要的。

http://nodejs.org/api/globals.html#globals_filename

关于javascript - Node.js 从模块内部获取模块的文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19305004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com