I'm working on a Dominos Pizza API right now, and everything seems to work when I console.log() it from the main module (bot.js). If I make a function in my testing file (testnearby.js) that tells it to console.log(localStore), it doesn't print anything. Code below. https://i.stack.imgur.com/ovJMD.png
The function defined that is not working (mentioned above) is getLocalStore
Any help would be appreciated. Code:
bot.js (main module):
//START
// TABLE OF THINGS ADDED TO BASKET ETC.
var store = "";
var localStore = null;
// FIND LOCAL STORE
exports.getLocalStore = function(postcode) {
// get the local store
// get the api and find with the postcode provided
// fetch the api
fetch('https://www.dominos.co.uk/storefindermap/storesearch?SearchText=' + postcode)
// json it
.then(res => res.json())
// return it
.then(function(json) {
// return console.log(json.localStore)
// makes it a variable so we can return it elsewhere
localStore = json.localStore
})
return localStore
}
// END
testnearby.js
// START
const ukdomino = require("./bot.js")
const postcode = "L129JH"
ukdomino.getLocalStore(postcode).then(localStore => console.log(localStore))
// END