You can get the custom or base URL of the store in a javascript(JS) file for the frontend area using the 'mage/url' widgets.
You have to pass the 'mage/url' widget as a dependency in a define([]) or require([]) function of the javascript file.

Hi ! ,
thank you for sharing knowledge , i’m trying to get the controller url inside a javascript file exactly like you did , but i have this error “Uncaught Error: Mismatched anonymous define() module: function (urlBuilder) {” do you have any idea why ? the code is just copy , paste for your above code and i’m using this : ‘rateExchange/index/index’ instead of your login url , this url that i’m trying to reach out (http://127.0.0.1/Magento_Extensions/rateExchange/index/index)