I've been reading about async and await in JS and tried to implement them in my code (which I totally messed up).
Here is my JS.
var express = require('express');
var router = express.Router();
var jsforce = require('jsforce');
const SEC_TOKEN = 'SEC_TOKEN';
const USER_ID = 'USER_ID';
const PASSWORD = 'PWD';
const { default: axios } = require('axios');
router.get("/", async (req, res, next) => {
  await initConnect;
  await soqlData;
  await slackPostTest;
});
initConnect = async () => {
  var conn = new jsforce.Connection({
    loginUrl: 'https://login.salesforce.com'
  });
  await conn.login(USER_ID, PASSWORD + SEC_TOKEN, (err, userInfo) => {
      if (err)
        console.log(err);
      else {
        console.log(userInfo.Id);
      }
    });
}
soqlData = async () => {
  await conn.query('Select Id, Name from Account LIMIT 1', (err, data) => {
      if (err)
        console.log(err);
      else
        return data.records[0];
    })
}
slackPostTest = async () => {
  await  axios.post('SLACK_WEBHOOK', {
      "text": "soqlRes"
    })
}
module.exports = router;
What I am trying to achieve?
- Initialize my connection by passing in SEC_TOKEN,USER_ID,PASSWORDto myinitConnectfunction this will give me a connection (conn).
- Use this connand query my salesforce instance and get some other data.
- post some message(currently irrelevant, but will hook up with the above response later) to my slack endpoint.
Also can someone please give me a little detailed explanation of the solution (in terms of async/await)?
Thanks
 
    