- Use
Deno.env.get("PORT")
in your serving function.
import { serve } from "https://deno.land/[email protected]/http/server.ts";
function handler(_req: Request): Response {
return new Response("Hello World!");
}
serve(handler, { port: Deno.env.get("PORT") });
- Create a file
deno.json
and add the starting command.
{
"tasks": {
"start": "deno run --allow-net --allow-env --allow-read main.ts"
}
}
-
To run locally, copy
.env.defaults
to a new file.env
, and modify.env
by assigning the port that you would like to run your application.cp .env.defaults .env
# in .env PORT=<your port>