Why is require.main.filename different on Azure that it is on my local windows machine?

azure, node.js

Solution

When you run your application on your local machine you probably execute following command

node.exe your_application.js

That is why `require.main.filename` returns the entry point of your application.

Please note that when you deploy your application to Windows Azure WebSite you use iisnode - a native IIS 7/8 module that allows hosting of Node.js applications in IIS 7/8. That is why `require.main.filename` returns `D:\Program Files (x86)\iisnode` on Windows Azure.

I would recommend using `__dirname` module local variable (usually combined with `path.join()` e.g. `var mydir = path.join(__dirname, '..')`) in order to obtain required directory.

I hope that explains your question.

Problem

On my local machine, this code: ``` var path = require('path'); var appdir = path.dirname(require.main.filename); console.log(appdir); ``` will log "c:\sites\mysite" On Azure, I see this instead: D:\Program Files (x86)\iisnode I know, from setting the node version to be my own that the path to my app is D:\home\site\wwwroot And, according to the docs "the entry point of the current application can be obtained by checking require.main.filename." Any ideas on what could be going wrong?

Original source