After passing my server side 'data' to the client I am unable to store the 'data' into a variable and receive an undefined.
Why is this happening and how can I resolve this?
The request is made on the client side:
(function () {
    var M;
    var url = '/app/get/metafield';
    fetch(url)
        .then((response) => response.json())
        .then(function (data) {
            filter(data)
        });
    function filter(data) {
        console.log('data :', data) // 25
        M = JSON.stringify(data);
    }
        console.log('M :', M) // undefined
});
This is ther server side code:
  app.get('/app/get/metafield', function (req, res, next) {
               function (error, response, body) {
                    var data = JSON.parse(body)
                    var M = data.metafields[0].value;
                    return res.json(M);
                })
    });
 
     
    