denoはいいぞ2019
入れ方
https://deno.land
https://deno.land/typedoc/index.html
code:bash
$ curl -fsSL https://deno.land/x/install/install.sh | sh
code:bashrc
export PATH=~/.deno/bin:${PATH}
確認
code:bash
$ deno -v
deno: 0.3.2
v8: 7.4.238
typescript: 3.2.1
書いてみる
code:ts
import {StringReader} from "https://deno.land/std@v0.3.2/io/readers.ts"
import open = Deno.open
const {copy} = Deno
async function main() {
const f = await open("README.md", "w")
await copy(f, new StringReader("Hello Deno!"))
f.close()
}
main()
型定義とtsconfig.jsonを作る
code:bash
$ deno types > deno.d.ts
code:tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"baseUrl": "/Users/keroxp/Library/Caches",
"paths": {
"https://*": "./deno/deps/https/*",
"http://*": "./deno/deps/http/*"
}
}
}
これでIntelliJ IDEAなら補完効くようになる
http server立ててみる
code:ts
import {listenAndServe} from "https://denopkg.com/keroxp/servest@v0.7.1/server.ts"
async function main() {
listenAndServe(":8888", async req => {
await req.respond({
status: 200,
headers: new Headers({
"content-type": "text/plain"
}),
body: new TextEncoder().encode("hello deno!")
})
});
}
main();