How to return data from a GET in back end

// Filename: backend/aModule.jsw (web modules need to have a .jsw extension)

import wixData from 'wix-data';

export function query(id) {

wixData.get("Articles", id)
  .then( (results) => {
   console.log(results)
 let item = results
  } )
  
return item //ERROR: 'item' is not defined
}

I can’t figure out a way to return the value, I’ve tried a global var but does not work

Hi carlos,

It is a matter of scoping in your javascript code.
However, even after fixing that, your code will still not work, since it is asynchronous.

Try just returning the wixData call:

export function query(id) {
  return wixData.get("Articales", id)
}

Try reading more about Javascript here: JavaScript Tutorial
and specifically, about Promises: Promise - JavaScript | MDN

Good luck,
Idan.