Answer the question
In order to leave comments, you need to log in
How to connect the necessary module in js?
Hello, I ran into a problem to connect a specific module in js.
There is a configs folder, where there are different js naming files site-name1-config.js, site-name2-config.js and so on. There is a folder with scripts, where the main.js file is located. At the beginning, a variable is set there, the name of the site, let's say site-name1.
So, the task is to load site-name1-config.js from configs into this main.js.
I tried using module.exports and require, but in the path inside require you cannot forward a variable like require('../configs/'+siteName+-config.js''). Can you tell me how else to solve this problem? Thanks
Answer the question
In order to leave comments, you need to log in
const site_1 = fs
.readdirSync(`${__dirname}/configs/`)
.filter((name) => site-name1-config\.js$/i.test(name))
.map((name) => require(`${__dirname}/configs/${name}`));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question