Deno with TypeScript - intro
Page content
Install
Follow to the official landig page.
curl -fsSL https://deno.land/x/install/install.sh | sh
Hello world
Here is first_script.ts
.
var msg:string = "Hello world"
console.log(msg)
This is written in TypeScript.
We can run the script by deno {{ your program name}}
.
Here is an example and result.
deno first_script.ts
Compile file:///Users/atlex/test/first_script.ts
Hello World
Run a simple web server with deno
Here is the program hellow_serve.ts
.
import { serve } from "https://deno.land/std@v0.40.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
- As of 2020/05/01,
v0.42.0
doesn’t work fine. - This program return the string “Hello World” to your browser.
Run with following command.
The only difference from “Hello world sample” is the option --allow-net
.
deno --allow-net hello_server.ts
You can access your page via http://localhost:8080
.
Update
deno upgrade