Node.js - getting current filename

后端 未结 8 870
执念已碎
执念已碎 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:40

    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);
    

提交回复
热议问题