const auth = { client: { id: 'xxxx' }, auth: { tokenHost: 'https://login.live.com/oauth20_authorize.srf' } }; const oauth2 = require('simple-oauth2'); async function getToken() { try { const result = await oauth2.clientCredentials.getToken(auth); console.log(result); // null const accessToken = oauth2.accessToken.create(result); console.log(accessToken); // null } catch (error) { return console.log(error.output); } } async function upload(fileName, path) { // upload to 1drive let stream = fs.createReadStream(path); return new Promise(async function (resolve, reject) { let token = await run(); console.log(token); onedriveAPI.items.uploadSimple({ accessToken: token, filename: fileName, driveId: "driveId", readableStream: stream, }).then((item) => { console.log(item); }); }); }