node.js - NodeJS Async/Await Exporting a Variable -


me again busting b***s ... i'm sorry have come guys, find information available online confusing , can't seem find appropriate answer problem. if 1 of wizards/gods of node me, i'd appreciate it.

i'm trying export variable yields promise different module. here's code:

the main:

//app.js <--- need variable exported.  var sp1 = require('./module');  var somepromise2 = new promise((resolve, reject) => {   resolve('hey! worked second time!'); });   async function exec() {   const message1 = await sp1.msg   const message2 = await somepromise2   console.log('success', message1, message2); }  exec() 

and module promise:

//module.js  var somepromise1 = new promise((resolve, reject) => {   var msg = '';   resolve(msg = 'hey! worked!'); });  module.exports = {   somepromise1, } 

as can see somepromise1, same somepromise2 in different module. thing is, apparently can't seem msg variable exported, yields undefined (if locally: in same file, works seemlessly).

thanks in advance , sorry in advance if find duplicate of existing question... i'crawled since yesterday answer , moved code around nothing seems apply...

you have error in importing , mistake in using promise:

//app.js <--- need variable exported.  var sp1 = require('./module').somepromise1;  var somepromise2 = new promise((resolve, reject) => {   resolve('hey! worked second time!'); });   async function exec() {   const message1 = await sp1;    const message2 = await somepromise2;   console.log('success', message1, message2); }  exec() 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -