Is there a way to import a module into another and run it only when called?
Actually i am importing like this.
import {getData, paginacao} from './restCountries.js'
Is there a way to import a module into another and run it only when called?
Actually i am importing like this.
import {getData, paginacao} from './restCountries.js'
there is a way to detect if your module is being imported or called directly and execute different parts of the file.
This has been answerred in this thread
if (require.main === module) {
console.log('called directly');
} else {
console.log('required as a module');
}