Node.js-获取当前文件名 [英] Node.js - getting current filename
本文介绍了Node.js-获取当前文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取当前文件名,函数名和行号?
How to get current file name, function name and line number?
我想将其用于记录/调试目的,等效于c中的__FILE__
,__LINE__
I want to use it for logging/debugging purpose, equivalent to __FILE__
, __LINE__
in c
推荐答案
Node.js为此提供了一个标准API:路径.
Node.js provides a standard API to do so: Path.
这样就很容易获得当前脚本的名称:
Getting the name of the current script is then easy:
var path = require('path');
var scriptName = path.basename(__filename);
这篇关于Node.js-获取当前文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文