Post image

We’re excited to announce the release of Neon’s Serverless Driver 0.9.0 on Deno’s JavaScript Registry JSR. Deno is an open-source JavaScript, TypeScript, and WebAssembly runtime built on V8, Rust, and Tokio. 

Although compatible with npm, Deno built JSR to address several changes and evolutions in the JavaScript ecosystem, including the adoption of ECMAScript Modules, the rise in popularity of TypeScript, and the emergence of new JavaScript runtimes such as Cloudflare Workers and Bun.

Think of JSR as npm optimized for TypeScript and ES modules, which works with Deno and all your Node, Bun, and Cloudflare Workers projects.

Why use Neon’s serverless driver in your Deno projects

The short answer: faster query latencies.

Neon is compatible with any Postgres driver, such as Postgres.js, node-postgres, etc. However, we built the serverless driver to allow V8-isolate runtimes such as Deno and Cloudflare Workers to connect to the database via protocols other than TCP. 

Our driver connects to the proxy over a WebSocket, telling the proxy which database host and port it wants to reach. We then worked to optimize for sub-10ms first query latencies, cutting by half the number of WebSocket roundtrips and then adding support for HTTP and connection caching.

Read more about HTTP vs. WebSockets: Which protocol for your Postgres queries at the Edge.

You can get started with the serverless driver using the deno add command:

deno add @neon/serverless

The above command will generate a deno.json file, listing all your project dependencies.

// deno.json

{
  "imports": {
    "@neon/serverless": "jsr:@neon/serverless@^0.9.0"
  }
}

You can then import the serverless driver to your hello.ts file:

// hello.ts

import { neon } from "@neon/serverless";

// Get the connection string from the environment variable "DATABASE_URL"
const databaseUrl = Deno.env.get("DATABASE_URL")!;
const sql = neon(databaseUrl);
const result = await sql`SELECT 'Hello World' as message`;

// [ { message: "Hello World" } ]

Run the following command to execute:

​​deno run -A hello.ts

Once you have finished writing your application, you can deploy it on Deno Deployvia a Github integration or deployctl:

deployctl deploy --project=<project-name> <application-file-name>

Conclusion

With the addition of Neon’s serverless driver to JSR, you can quickly add the driver to your project dependencies and run sub-10ms queries on multiple JavaScript runtimes, including Deno, Cloudflare, Bun, and Node. 

Try Neon for free now. Join us on Discord, follow us on X, and let us know how we can make your experience using Neon and Postgres better. Happy coding!