ThomasReggi
ThomasReggi

Reputation: 59345

Execute require contents more then once

Let's say I have an log.js with console.log('hi'), and in another file I have this:

require('./example.js')
require('./example.js')
require('./example.js')

I only get one console.log of hi.

What do I have to do so that hi is logged 3 times?

Upvotes: 0

Views: 19

Answers (1)

ThomasReggi
ThomasReggi

Reputation: 59345

require('./example.js')
delete require.cache[require.resolve('./example.js')]
require('./example.js')
delete require.cache[require.resolve('./example.js')]
require('./example.js')

Upvotes: 1

Related Questions