OneCompiler

the new discovery

Deno 2 is the latest release of the secure JavaScript and TypeScript runtime, featuring significant improvements in dependency management, compatibility with popular JavaScript frameworks, and a refined permission system. In this tutorial, you'll learn how to get started with Deno 2, explore its key features, and understand why it's an exciting alternative to Node.js.

Following is a quick showcase of a deno 2 hello world server

1 Answer

1 year ago by

// Import necessary modules from Deno
import { serve } from "https://deno.land/[email protected]/http/server.ts";

// Define the handler function
const handler = async (req: Request): Promise<Response> => {
// Parse the URL query parameters
const url = new URL(req.url);
const name = url.searchParams.get("name") || "World";

// Create the response message
const message = { greeting: Hello, ${name}! };

// Return the JSON response
return new Response(JSON.stringify(message), {
headers: { "Content-Type": "application/json" },
status: 200,
});
};

// Start the server on port 8000
console.log("Server running on http://localhost:8000/");
serve(handler, { port: 8000 });

1 year ago by senpie956