Ad

How Can I Get Current Store Details In Shopify App Front-end Using Node And Express

I am developing shopify public app with node.js and express and want to know that how can get the current store details at my app front-end when store admin open my app

I am getting store details at back-end side in query_string when store admin click on navigation link of my app but not able to get at front-end side with jquery or javascripts and I am using express and ejs view templating for front-end

can any one please help me out this that how to manage current store details at front-end side. Thank you

Ad

Answer

I got the solution to access store details at my shopify app front-end as following

require changes => use 'cookie' npm package for storing data in cookies and also set cookie as like this in your controller

   const cookie = require('cookie');

  app.get('/',(req,res)=>{
    const data=req.query;
    res.cookie('shop_detail',data);
});

get cookie from your front-end use following javascript function

      function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
          var c = ca[i];
          while (c.charAt(0)==' ') c = c.substring(1,c.length);
          if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
          }
          return null;
      }

call this function like this

readCookie('shop_detail');
Ad
source: stackoverflow.com
Ad