How to get drupal module path in javascript? I'm trying to use this: var path = Drupal.settings.mymodule.basePath;but I'm getting this error: Uncaught TypeError: Cannot read property 'basePath' of undefined.
First of all you need to call drupal_add_js() with a 'settings' parameter. This will inform your Drupal.settings javascript namespace about the settings/variables you need in this file via drupal. Try the following :

Lets suppose you want to call a specific *.js file on a nodes' view page, call it as :

drupal_add_js(array('myModule' =&gt; array('basepath' =&gt; '&lt;your-drupal-base-path&gt;')), 'setting');


This basepath is global and you can get it in any *.js file called at this point. Next, you can use this basepath in your *.js file as :

var path = Drupal.settings.myModule.basepath;