I am trying to create a SupaDB client for Steam, more info. When I check the website console, I get the following error message, even when node file.js is used, same error is being given. Which the error is:
SyntaxError: await is only valid in async functions and the top level bodies of modules
As the info provided, the error also includes that the line where the error occurs is line 8...
Full log:
const { data, error } = await supabase.from("steam").select("*")
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules at Object.compileFunction (node:vm:352:18) at wrapSafe (node:internal/modules/cjs/loader:1031:15) at Module._compile (node:internal/modules/cjs/loader:1065:27) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:17:47
const supabase = createClient("https://gqkuommdmfzmwkzdewma.supabase.co",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imdxa3VvbW1kbWZ6bXdremRld21hIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NDkyNjQyNTIsImV4cCI6MTk2NDg0MDI1Mn0.iF651HDhqynAQRlG8T6wFS3ZEx4dqxHiEiguc0m7-zI", {
headers: {
Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZWNyZXQiOiI3MjU5YTg2ZDVlMTE1YTM2ODRjMjdlNGUiLCJpYXQiOjE2NTAyODg1MzJ9.43EriTTwaDLeepFTbRoZXJksqCtIrjMZ-yHHMDuK0_4"
}
})
const { data, error } = await supabase.from("steam").select("*")
if (error) {
console.log('Error occurred:', error)
}
else {
console.log(data)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- link CSS and JavaScript to HTML -->
<link rel="stylesheet" href="style.css">
<script src="code.js"></script>
</head>
<body>
</body>
</html>