I am writing a small javascript library, it uses an image. I want to create a directory structure as follows:
/ lib
/ mylib
main.js
/ img
main.png
/ other libraries ...
index.html
But if I hardcode the image path lib/mylib/img/main.png , my library cannot be used in another directory structure.
I want to use the "relative path", which is relative to main.js. itself. So that I can write path + 'img/main.png' to access the image.
How can I find out where main.js is?
source share