I'm working on something on NodeJS and I'm using the import keyword from the ES6 syntax.. and I want to execute immediately after calling it. I searched for similar thoughts to do that but nothing was helpful enough.
What I want to do is basically transform the following code from the CommonJS into the ES6.
// In CommonJS:
var birds = require('./birds')()
// In ES6:
import birds from './birds'()
I can do that using the const keyword:
import birds from './birds'
const SomethingButNotBirds = birds()
But, I really wanna know if there's a better way to do it.
I really appreciate your help guys!
ES6 import statement has a declarative syntax and does not give you room to execute functions just as you'd do with require()().
The code you have below is the only valid way of doing it.
import birds from './birds'
const SomethingButNotBirds = birds()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With