import moment from 'moment'; import * as vnUtils from './utils.js'; import dotenv from 'dotenv'; dotenv.config(); import models from './models/index.js'; let tokenExpirationDate = await vnUtils.getClientToken(models); try { setInterval(async () => { console.log('Querying the API to check for new data...'); vnUtils.getTradeitems(8714231154815); console.log('Current token expiration date: ', tokenExpirationDate); if (moment().isAfter(tokenExpirationDate)) { console.log('Token expired, getting a new one...'); tokenExpirationDate = await vnUtils.getClientToken(models); } }, process.env.STATUS == 'development' ? 10000 : 20000); } catch (error) { console.error('Unable to connect to the database:', error); } console.log = function () { let args = Array.prototype.slice.call(arguments); args.unshift(new moment().format('HH:mm:ss') + ' -'); console.info.apply(console, args); };