neondatabase / serverless

Connect to Neon PostgreSQL from serverless/worker/edge functions
https://www.npmjs.com/package/@neondatabase/serverless
MIT License
318 stars 11 forks source link

How to use serverless in the browser? #80

Closed ceving closed 2 months ago

ceving commented 2 months ago

I tried this, but serverless.mjs does not export neon.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <script type="module">
      // about:config -> security.fileuri.strict_origin_policy -> false
      import * as neon from './serverless/dist/serverless.mjs';
      console.log(neon);
      const url = 'postgresql://***';
      const sql = neon(url);
    </script>
  </head>
  <body>
  </body>
</html>

The output is just:

Array(4) [ "batchQueryTest", "cf", "latencies", "neonConfig" ]
jawj commented 2 months ago

Try import { neon } from './serverless/dist/npm/index.mjs'. Or use the npm package and bundle it in.

ceving commented 2 months ago

Thanks. This works!

jawj commented 2 months ago

Great.