deno さわってみるレポジトリ
- a JavaScript/TypeScript runtime with secure defaults and a great developer experience. made by Ryan Dahl who is also author of Node.js
- released v1.0 on 2020/05/13.
- speach by author with retrospective of Node.js: https://youtu.be/M3BM9TB-8yA?t=987
- エコシステムが非常によくできておりさわってて快適。ただし、まだ各種ライブラリが Node.js に対して圧倒的に不足してるのでまだプロダクションでは使いにくいか。OSS コミットチャンス!!! ✊
- 公式アイコンがかわいい
- Secure by default. No file, network, or environment access (unless explicitly enabled) (More detail: https://deno.land/manual@v1.4.4/getting_started/permissions)
- Supports TypeScript by default.
- Ships a single executable
- Has built-in utilities(e.g. dependency inspector, code formatter)
- 標準ライブラリあるよ。(Go から輸入してるらしい) https://deno.land/std@0.73.0
- Scripts can be bundled into a single JavaScript file.
- does not use
npm
(module URLs instead of it) - does not use
package.json
in its module resolution algorithm.(he says it's a noise.) - All async actions return a promise. (good bye callback hell)
cf: https://deno.land/manual#comparison-to-nodejs, https://qiita.com/so99ynoodles/items/c3ba2a528052827e3b3c
https://deno.land/manual の 1.Introduction, 2.Getting Started(2.3 First steps まで) までフォローして、あとは 6. Examples をいくつか。 そしてちょっとそれっぽいコードを。
- setup
$ brew install deno
$ deno --version
deno 1.4.4
v8 8.7.75
typescript 4.0.3
-
getting started
$ deno run https://deno.land/std@0.73.0/examples/welcome.ts
Download https://deno.land/std@0.73.0/examples/welcome.ts
Check https://deno.land/std@0.73.0/examples/welcome.ts
Welcome to Deno 🦕
- getting started with local code
https://deno.land/manual@v1.4.4/examples/hello_world
$ deno run hello-world.ts
Hello John
Hello Sarah
Hello Kai
- webserver.ts https://deno.land/manual@v1.4.4/examples/http_server
$ deno run --allow-net webserver.ts
Check file:///Users/shogokakinouchiv2/study/play-with-deno/webserver.ts
HTTP webserver running. Access it at: http://localhost:3000/
ここからちょっとそれっぽいやつ。
-
エンドポイントはやしてみる。
フレームワークは https://github.com/sholladay/pogo を選択。
https://github.com/kakinouchi/play-with-deno/blob/main/src/application/sample/sample.controller.ts -
working with pm2
-
webserver.ts コピってみたらエディタに怒られた。 .vscode/settings.json を作って、
"deno.enable": true
と書けばよし(language server が有効になる)。 https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno -
コードを書いてるとホットリロードしたくなるのが人情というもの。 Denon というライブラリを使うとできるっぽい。https://deno.land/x/denon@2.4.1 コマンド一発叩いて、パス通しておわり。
$ deno install -qAf --unstable https://deno.land/x/denon@2.4.0/denon.ts
以後、
deno
コマンドの代わりにdenon
コマンドを使う。(わかりにくい!しかもちょいバグってるっぽい!--unstable なだけある。)
- https://deno.land/
- https://deno.land/manual <- これがガイドとしてよくできてる。
- https://flaviocopes.com/deno/ <- 実践的にはこれ。