What is Deno?
Deno is a secure runtime for JavaScript and TypeScript, built on V8 and Rust, with built-in TypeScript support.
Basic Deno Server
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
serve(async (req) => {
const url = new URL(req.url);
if (url.pathname === "/api/users" && req.method === "GET") {
const users = [
{ id: 1, name: "John", email: "john@example.com" }
];
return new Response(JSON.stringify(users), {
headers: { "Content-Type": "application/json" }
});
}
return new Response("Not Found", { status: 404 });
}, { port: 8000 });
Running Deno
# Run server
deno run --allow-net server.ts
Best Practices
- Use TypeScript by default
- Import from URLs directly
- Use built-in security features
- Handle errors properly
- Use standard library modules