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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -