Hi! Today I am going to talk about one of the most useful Emacs functions I have written. I use it almost every day while developing Javascript.

The Javascript project I work on is pretty big and has deep folder structures. When you want to import a Javascript file you need to know the path to that file relative to the current file. For me it’s really annoying to manually thinking about where that path is and I many times make an error. Was it "../../../frontend/components/Test.js" or "../../frontend/components/Test.js" ?

Because I am an Emacs user I wrote a simple script to automatically generate the import statment with the relative file path to the file. The scripts uses ido to let the user select the js-file in the projectile project, and then calculates the relative path and inserts it wherever the cursor currently is.

I am just going to leave the script here: (EDIT: I created js-import if you want to use this!)