(async () => { try { let result = await feathersApp.logout(); console.log(‘the result is: ‘ + result) } catch (e) { console.log(e); } } ) () ;
(async () => let logoutResult = await feathersApp.logout(); console.log(logoutResult); })().catch(e => { console.log(e) });
https://stackoverflow.com/questions/70883305/best-way-to-make-a-knex-request-from-inside-a-promise
from grokling slack:
return sequelizeTable.create({‘column1’:‘data one’,‘column2’:‘data two’}) // Chain on .create .then(result => sequelizeTable.count( { ‘where’ : { ‘id’ : result.id } } ) // Chain on .count .then(count => console.log(count)) // Here we return result to be used after this .then(() => result) ) .then(result => console.log(result.id)) .catch(err => console.log(‘ERROR ‘ + err))
If you don’t want to make smaller functions to make your code more readable, you’d do it something like this:
return table.create(…..)
.then( result => {
return table.count( { ‘where’‘ : {‘id’: result.id }}));
.then (count => {
console.log(count));
return count;
})
.then (count => {
if ( count > 123 ) console.log(” > 123: “ + result.id) else
console.log ( “<= 123: “ + result.id );
return something;
})
})
.catch( …….)
NODE:
‘use strict’
/*
function connect() {
return new Promise( (resolve, reject) => {
client.rpc.make (‘promise’, ‘provide data passed in – abcde’, (err, reply) => {
resolve(reply)
});
})
}
connect()
.then( (result1) => { return(‘RESULT1: ‘ + result1); })
.then( (result2) => { return(‘RESULT2: ‘ + result2); })
.then( (result3) => { console.log(‘RESULT 3: ‘ + result3); })
;
*/