In node.JS how can I get the path of a module I have loaded via require that is *not* mine (i.e. in some node_module)

前端 未结 7 1631
清歌不尽
清歌不尽 2020-12-02 15:16

I require a module that was installed via npm. I want to access a .js file subordinate to that module (so I can subclass a Constructor method in it). I can\'t (well, don\'t

相关标签:
7条回答
  • 2020-12-02 15:53

    If I correctly understand your question, you should use require.resolve():

    Use the internal require() machinery to look up the location of a module, but rather than loading the module, just return the resolved filename.

    Example: var pathToModule = require.resolve('module');

    0 讨论(0)
提交回复
热议问题