1

In asp.net, I can use Server.MapPath("~/") to get the root path of my application. Is there any environment variable I can access via process.env or any other method to get the root path in node.js? I'm using iisnode.

Thanks

Arun
  • 3,036
  • 3
  • 35
  • 57

1 Answers1

1

There are more than one ways to do that:

__dirname - The directory of the current module

__filename - The full path to the current module

process.cwd() - The working directory of the app

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • All of these give me the folder of the current .js file. What I want to obtain is the folder where the IIS app is installed - c:\inetpub\wwwroot\app\. The above commands give me c:\inetpub\wwwroot\app\user\adduser – Arun Aug 13 '19 at 08:22
  • I believe this is the correct answer, I am wondering why the question did not describe the IIS configuration. If IIS is configured with a virtual folder or IIS added an application to the root server, the folder that is returned with the three options described above, will describe the folder that was set in IIS. This is exactly what I see when testing this answer - it works for me! Thanks Charlie... – Harvey Mushman Jul 29 '23 at 14:21