{"action":"created","issue":{"url":"https://api.github.com/repos/MONEI/Shopify-api-node/issues/191","repository_url":"https://api.github.com/repos/MONEI/Shopify-api-node","labels_url":"https://api.github.com/repos/MONEI/Shopify-api-node/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/MONEI/Shopify-api-node/issues/191/comments","events_url":"https://api.github.com/repos/MONEI/Shopify-api-node/issues/191/events","html_url":"https://github.com/MONEI/Shopify-api-node/issues/191","id":329851409,"node_id":"MDU6SXNzdWUzMjk4NTE0MDk=","number":191,"title":"Share one Shopify instance across Express app","user":{"login":"tomblanchard","id":3143764,"node_id":"MDQ6VXNlcjMxNDM3NjQ=","avatar_url":"https://avatars0.githubusercontent.com/u/3143764?v=4","gravatar_id":"","url":"https://api.github.com/users/tomblanchard","html_url":"https://github.com/tomblanchard","followers_url":"https://api.github.com/users/tomblanchard/followers","following_url":"https://api.github.com/users/tomblanchard/following{/other_user}","gists_url":"https://api.github.com/users/tomblanchard/gists{/gist_id}","starred_url":"https://api.github.com/users/tomblanchard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomblanchard/subscriptions","organizations_url":"https://api.github.com/users/tomblanchard/orgs","repos_url":"https://api.github.com/users/tomblanchard/repos","events_url":"https://api.github.com/users/tomblanchard/events{/privacy}","received_events_url":"https://api.github.com/users/tomblanchard/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-06-06T12:44:13Z","updated_at":"2018-06-07T15:15:47Z","closed_at":"2018-06-07T15:02:55Z","author_association":"NONE","body":"I'm developing a Shopify app which uses Express and this module for API calls and I've run into trouble sharing one Shopify instance across my routes. Here's a stripped down version of what I'm trying to achieve:\r\n\r\n```javascript\r\nvar express = require(\"express\");\r\nvar Shopify = require(\"shopify-api-node\");\r\nvar app = express();\r\n\r\n// Declare at highest scope so all routes can reference it\r\nvar shopify;\r\n\r\napp.get(\"/\", (req, res) => {\r\n  var { shopName, apiKey, password } = req.query;\r\n\r\n  // Re-declare to a Shopify instance using data from query string parameter\r\n  shopify = new Shopify({ shopName, apiKey, password });\r\n\r\n  shopify.shop.get()\r\n    .then((shop) => {\r\n      return res.send(JSON.stringify(shop));\r\n    })\r\n    .catch(() => {\r\n      return res.status(500).send(\"Something broke.\");\r\n    });\r\n});\r\n\r\napp.get(\"/other-route\", (req, res) => {\r\n  shopify.product.list()\r\n    .then((products) => {\r\n      return res.send(JSON.stringify(products));\r\n    })\r\n    .catch(() => {\r\n      return res.status(500).send(\"Something broke.\");\r\n    });\r\n});\r\n\r\napp.listen(3000, () => {\r\n  console.log(\"Example app listening on port 3000!\")\r\n});\r\n```\r\n\r\nThat actually works like how I want it to:\r\n\r\n- Visit a URL like: http://localhost:3000/?shopName=your-shop-name&apiKey=your-api-key&password=your-app-password\r\n- API call works\r\n- Visit the URL: http://localhost:3000/other-route\r\n- API calls works\r\n\r\nWhat I'm struggling with is eventually all routes will be in separate files, how could I share that one Shopify instance between all files?\r\n\r\nIn my actual non-stripped-down app I'm using express-session, I tried storing the Shopify instance in that but that only takes JSON-serializable data so that doesn't work. Is there an Express-best practice I've missed when it comes to storing instances across routes/session? \r\n\r\nRight now I'm creating a new Shopify instance for each route which isn't ideal, it works but eventually I'll run into problems with the API call limit, I'd prefer to use one Shopify instance across all of my routes with `autoLimit: true` and not have to worry about it, any help would be greatly appreciated.\r\n\r\nPS: Thanks once again for this module, it's great."},"comment":{"url":"https://api.github.com/repos/MONEI/Shopify-api-node/issues/comments/395458383","html_url":"https://github.com/MONEI/Shopify-api-node/issues/191#issuecomment-395458383","issue_url":"https://api.github.com/repos/MONEI/Shopify-api-node/issues/191","id":395458383,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NTQ1ODM4Mw==","user":{"login":"lpinca","id":1443911,"node_id":"MDQ6VXNlcjE0NDM5MTE=","avatar_url":"https://avatars0.githubusercontent.com/u/1443911?v=4","gravatar_id":"","url":"https://api.github.com/users/lpinca","html_url":"https://github.com/lpinca","followers_url":"https://api.github.com/users/lpinca/followers","following_url":"https://api.github.com/users/lpinca/following{/other_user}","gists_url":"https://api.github.com/users/lpinca/gists{/gist_id}","starred_url":"https://api.github.com/users/lpinca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lpinca/subscriptions","organizations_url":"https://api.github.com/users/lpinca/orgs","repos_url":"https://api.github.com/users/lpinca/repos","events_url":"https://api.github.com/users/lpinca/events{/privacy}","received_events_url":"https://api.github.com/users/lpinca/received_events","type":"User","site_admin":false},"created_at":"2018-06-07T15:15:47Z","updated_at":"2018-06-07T15:15:47Z","author_association":"COLLABORATOR","body":"Yes this is more or less what I was suggesting, the only problem is that it may create a leak if the session is destroyed and the corresponding instance is not removed from the map."}}
{"actor":{"display_login":"lpinca"}}