How create other js file and put my code on it and import it to main-page.js


#1

Screenshot (7)

this is the structure of my app folder I want to create other js file and write code to it after import it to my main page any idea how to do that’s and thanks in advance


#2

you can put the new js file anywhere in the app folder (usually u put it inside a folder named shared), then just make sure you add any var or function you want to the exports. e.g.

const backendAPI = {
    Login: function(username) {
        console.log(username + "is logged in");
    },
    Logout: function() {
        console.log("logging out");
    }
}
exports.backendAPI = backendAPI;

now you can import it in any other js file with

const myAPI = require("~/shared/shared.js").backendAPI;

and can use function for example

myAPI.Login(user);
myAPI.Logout();

#4

thanks, man I well try it