Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.mainModule is deprecated in nodejs

module.exports = path.dirname(process.mainModule.filename)

Main Module Deprecated

process.mainModule.filename is deprecated in nodejs. Is there any alternative method to get a current directory of the file?

like image 302
Yashwanth M Y Avatar asked Jun 26 '26 20:06

Yashwanth M Y


1 Answers

  • The entry point of the current application can be obtained by checking require.main.filename.
  • __dirname gets you the directory the module is in.
  • process.cwd() gets the current working directory.

Chances are you want one of these.

like image 128
AKX Avatar answered Jun 28 '26 12:06

AKX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!