gpt4 book ai didi

node.js - 如何检测 Node.js 中的入口文件?

转载 作者:搜寻专家 更新时间:2023-10-31 23:01:59 24 4
gpt4 key购买 nike

如何检测Node.js中的入口文件?

例如,如果我通过键入 node file1.js 启动我的应用程序,我怎么知道 file1.js 是入口点?

最佳答案

你也可以使用require.main

Accessing the main module When a file is run directly from Node, require.main is set to its module. That means that you can determine whether a file has been run directly by testing

require.main === module

For a file foo.js, this will be true if run via node foo.js, but false if run by require('./foo').

Because module provides a filename property (normally equivalent to __filename), the entry point of the current application can be obtained by checking require.main.filename.

hot sauce

关于node.js - 如何检测 Node.js 中的入口文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31643041/

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