• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

deno

date: 2022-02-05 excerpt: denoの使い方

tag: denotypescriptnode


denoの使い方

概要

  • typescriptをサーバサイドで実行するもの
  • typescriptのコンパイルやjsへ変換することができる
    • 現時点ではbundleはnodeやブラウザで動かすとは期待していない

インストール

$ curl -fsSL https://deno.land/install.sh | sh
  • カスタムパスにインストールされるのでパスを有効化する

基本

スクリプトの実行

$ deno run script.ts

コンパイル

$ deno compile script.ts

サンプルコード

welcome.ts

console.log("Welcome to Deno!");

cat.ts

import { copy } from "https://deno.land/std@0.125.0/streams/conversion.ts";
for (const filename of Deno.args) {
  const file = await Deno.open(filename);
  await copy(file, Deno.stdout);
  file.close();
}

curl.ts

const url_ = Deno.args[0];
const res = await fetch(url_);

const body = new Uint8Array(await res.arrayBuffer());
await Deno.stdout.write(body);


denotypescriptnode Share Tweet