I'm using Javascript without HTML, just JavaScript with Node and I need some other js files so it does not take up too much space on the main file. And I was looking for, and I found something like "module.exports", but I did not understand it so well, can anyone explain this to me?
I've tried this
var xgr = require("./xgr.js").randomString;
randomString();
In the other file
function randomString() {
var carac = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var rand = Math.floor(Math.random() * carac.length);
var gerado = carac[rand];
return gerado;
}
module.exports = randomString;
xgr()instead ofrandomString()because that is the name you gave to the function when you've imported it.