The code in your question seems fine, but I suspect that you have a typo in the actual module file on your computer. Here's why:
When I run the code in your question, it works as expected:
Note, I removed the extra console.log
statement you had in your example before the invocation of serve(handler)
:
so-74582168.ts
:
import { serve } from "https://deno.land/std@0.166.0/http/server.ts";
function handler(_req: Request): Response {
return new Response("Hello, World!");
}
serve(handler);
% deno run --allow-net so-74582168.ts
Listening on http://localhost:8000/
Looks good. However, when I replace the import specifier with the one in your error message, this is the error that I see in the console when I try to run the modified program:
so-74582168.ts
:
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";
function handler(_req: Request): Response {
return new Response("Hello, World!");
}
serve(handler);
% deno run --allow-net so-74582168.ts
error: Module not found "https://deno.land/std@$STD_VERSION/http/server.ts".
at file:///Users/deno/so-74582168.ts:1:23
Double-check your actual source file module. Try copying and pasting the exact code from my first code block above into your file, save it, and then run it again using the command I showed (including the net
permission argument after deno run
): it should work.