javascript - Nodejs - how group and export multiple functions in a separate file? -
how can group , export multiple functions in nodejs?
i trying group util functions in utils.js:
async function example1 () { return 'example 1' } async function example2 () { return 'example 2' } module.exports = { example1, example2 }
and imported in home.js:
import { example1, example2 } '../utils' router.get('/', async(ctx, next) => { console.log(example1()) // promise { 'example 1' } })
i thought 'example 1'
test case above?
any ideas?
this solution exporting problem! , don't mix es5 exports
es6 imports
, can weird - sometimes!
export const example1 = async () => { return 'example 1' } export const example2 = async () => { return 'example 2' } // other file import { example1, example2 } '../../example' return example1()
nevertheless if have mix them, let me know! can find solution aswell!
more exporting modules , can go wrong!
mdn exports , short story the state of javascript modules
Comments
Post a Comment