-2

In my first file : pro.js

const newly = async function getBalance(account,address){
    
    const resp = await fetch(
      `https://api-link`,
      {
        method: 'GET',
        headers: {
          'api-key': ....
        }
      }
    );
    
    account = await resp.json();
    return account;
  }

module.exports = {
    newly
}


second file : index.js

const myNewly = require('./pro');

app.post('/getBalance/type',jsonParser,function(req,res){

  
  console.log(myNewly.newly(account,req.body.address)); // return Promise { <pending> }
  
  res.send(myNewly.newly(account,req.body.address)); // return nothing in postman
  
})
Konrad
  • 21,590
  • 4
  • 28
  • 64
Oswald
  • 1
  • 2

1 Answers1

-3

Either use async

app.post('/getBalance/type',jsonParser,async function(req,res){
  res.send(await myNewly.newly(account,req.body.address));
})

Or then

app.post('/getBalance/type',jsonParser,function(req,res){
  myNewly.newly(account,req.body.address).then(data => {
    res.send(data);
  }
})
Konrad
  • 21,590
  • 4
  • 28
  • 64