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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With