Node.js - getting current filename

后端 未结 8 871
执念已碎
执念已碎 2020-12-13 08:04

How to get current file name, function name and line number?

I want to use it for logging/debugging purpose, equivalent to __FILE__, __LINE__

8条回答
  •  醉话见心
    2020-12-13 08:44

    Well, I wanted to use the file name as the tag for the logger so the most straight forward and what I wanted is this:

    __filename.substring(__dirname.length + 1, __filename.lastIndexOf("."))
    

提交回复
热议问题