えぐろぐ

https://twitter.com/eggpogg

Denoを触ってみる

先日Ver.1.0.0がリリースされたで少し触ってる.

deno.land

まずはIntroductionを読んで見る.

deno.land

インストール

インストール方法はinstallationをそのままなぞる.

僕はmacの環境なので,いいかのコマンドを実行.

curl -fsSL https://deno.land/x/install/install.sh | sh

完了後に,DENO_INSTALLPATHの追加 bash_profileに設定してとあったので追加

######################################################################## 100.0%######################################################################### 100.0%
Archive:  /Users/nitroplus/.deno/bin/deno.zip
  inflating: deno                    
Deno was installed successfully to /Users/nitroplus/.deno/bin/deno
Manually add the directory to your $HOME/.bash_profile (or similar)
  export DENO_INSTALL="/Users/eggpogg/.deno"
  export PATH="$DENO_INSTALL/bin:$PATH"
Run '/Users/nitroplus/.deno/bin/deno --help' to get started

~ 2m 53s

パスを通して,動作確認

❯ deno -V
deno 1.0.0

❯ deno run https://deno.land/std/examples/welcome.ts
Download https://deno.land/std/examples/welcome.ts
Warning Implicitly using master branch https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕

アップデートは以下のコマンドで実行されるみたい.

 deno upgrade

Homebrewもありました(汗)

brew install deno

すでに複数バージョン振り分け用のツールもあるみたい.
※ 入れてからスクロールして気づいたので,今回は入れていない.

github.com

開発環境

Intellij IDEA

IDEは普段はIntellij IDEAを使っているので,Denoが対応されているか確認してみた.

結論は 2020年5月16日 現在 は未対応とのこと. とりあえず,待ちみたい.

Denoを入れてほしいという話は,2019年1月からForum上で話があるみたい.

intellij-support.jetbrains.com

issueもあがっているみたいで,ver1.0.0がリリースされるとのことで,ここ1週間はだいぶ人が集まっている状態.

https://youtrack.jetbrains.com/issue/WEB-41607

VSCode

VSCodeはサポートプラグインがあるみたいなので,VSCodeで書いてみる. 4つくらいプラグインがあったけど,1番インストール数がおおいこれを採用.

github.com

サンプルの実行

httpサーバーのコード

import { serve } from "https://deno.land/std/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" });
}

実行

npmと違って,実行時にモジュールのダウンロードが挟まるみたい.

❯ deno run --allow-net ./index.ts
Compile file:///Users/nitroplus/workspaces/HelloDeno/index.ts
Download https://deno.land/std/http/server.ts
Warning Implicitly using master branch https://deno.land/std/http/server.ts
Download https://deno.land/std/encoding/utf8.ts
Download https://deno.land/std/io/bufio.ts
Download https://deno.land/std/testing/asserts.ts
Download https://deno.land/std/async/mod.ts
Download https://deno.land/std/http/_io.ts
Warning Implicitly using master branch https://deno.land/std/async/mod.ts
Warning Implicitly using master branch https://deno.land/std/testing/asserts.ts
Warning Implicitly using master branch https://deno.land/std/encoding/utf8.ts
Warning Implicitly using master branch https://deno.land/std/io/bufio.ts
Warning Implicitly using master branch https://deno.land/std/http/_io.ts
Download https://deno.land/std/io/util.ts
Warning Implicitly using master branch https://deno.land/std/io/util.ts
Download https://deno.land/std/path/mod.ts
Warning Implicitly using master branch https://deno.land/std/path/mod.ts
Download https://deno.land/std/path/win32.ts
Download https://deno.land/std/path/posix.ts
Download https://deno.land/std/path/common.ts
Download https://deno.land/std/path/separator.ts
Download https://deno.land/std/path/interface.ts
Download https://deno.land/std/path/glob.ts
Warning Implicitly using master branch https://deno.land/std/path/interface.ts
Warning Implicitly using master branch https://deno.land/std/path/posix.ts
Warning Implicitly using master branch https://deno.land/std/path/common.ts
Warning Implicitly using master branch https://deno.land/std/path/separator.ts
Warning Implicitly using master branch https://deno.land/std/path/glob.ts
Warning Implicitly using master branch https://deno.land/std/path/win32.ts
Download https://deno.land/std/path/_constants.ts
Download https://deno.land/std/path/_util.ts
Warning Implicitly using master branch https://deno.land/std/path/_constants.ts
Warning Implicitly using master branch https://deno.land/std/path/_util.ts
Download https://deno.land/std/fmt/colors.ts
Download https://deno.land/std/testing/diff.ts
Warning Implicitly using master branch https://deno.land/std/fmt/colors.ts
Warning Implicitly using master branch https://deno.land/std/testing/diff.ts
Download https://deno.land/std/path/_globrex.ts
Warning Implicitly using master branch https://deno.land/std/path/_globrex.ts
Download https://deno.land/std/async/deferred.ts
Download https://deno.land/std/async/delay.ts
Download https://deno.land/std/async/mux_async_iterator.ts
Warning Implicitly using master branch https://deno.land/std/async/delay.ts
Warning Implicitly using master branch https://deno.land/std/async/deferred.ts
Warning Implicitly using master branch https://deno.land/std/async/mux_async_iterator.ts
Download https://deno.land/std/textproto/mod.ts
Download https://deno.land/std/http/http_status.ts
Warning Implicitly using master branch https://deno.land/std/http/http_status.ts
Warning Implicitly using master branch https://deno.land/std/textproto/mod.ts
Download https://deno.land/std/bytes/mod.ts
Warning Implicitly using master branch https://deno.land/std/bytes/mod.ts
http://localhost:8000/

ローカルでWebサーバーがとりあえず動いた. f:id:eggpogg:20200516160855p:plain

締め

TypeScriptを触ったことがあったので,Denoの実行環境とか言語思想とかを理解できれば使えそうだなと感じた.

package.jsonがなくなるのは結構嬉しい.
開発中にnode_modulesに入っているけど,package.jsonに入れ忘れるとか結構あったし,名前解決あたりで苦労したことがあったので.

あと,Ver1.0.0のリリースにしてはサンプルコードの多さやドキュメントがしっかりしていてわかりやすかった.

また,次の機会に他のサンプルコードとか読んでみようと思う.

Denoロゴはかわいい.

https://deno.land/images/deno_logo.png

github.com

てか,DenoってNodeを逆にした言葉なんだ!と最後の最後で気づいたw