Deno 入門指南
  • 前言
  • Deno 更新日誌
  • 簡介
    • Deno 跟 Node.js 的主要差異
    • Hello, World!
  • TypeScript 基礎篇
    • 變數宣告
    • 使用型別系統
    • 流程判斷與迴圈
    • 函式宣告
    • This 與 Arrow Function
    • 在函式中應用強型別
    • 介面
    • 型別別名
    • 物件導向概念
    • 類別的封裝與繼承
    • 介面與類別、抽象類別
    • 泛型的概念與實作
    • 型別補充
  • Deno CLI
    • 快速開始
    • 沙盒機制
    • URL Import
    • 編譯選項
    • 相關工具及測試
      • WebGPU API
      • Deno.resolveDns
      • 程式碼編譯器
      • 程式碼檢查器
      • 依賴檢查器
      • 文件產生器
      • 程式碼打包工具
      • 腳本安裝
      • 程式碼格式化
      • Deno 命名空間與編譯器 API
      • 使用 Deno 進行測試
  • 使用 Deno 打造多線程應用
    • 多線程概念
    • Deno Workers
    • 使用多線程計算矩陣相乘
  • 使用 Deno 打造 Web API
    • Web API 介紹
    • Oak 框架介紹
    • 使用 Denon 精簡指令
    • 實作 Web API
    • MongoDB 安裝教學
    • Deno 與 MongoDB 共舞
    • 完成第一支 Web API
    • 淺談跨來源資源共用(CORS)與解決辦法
Powered by GitBook
On this page

Was this helpful?

  1. Deno CLI
  2. 相關工具及測試

腳本安裝

腳本安裝

Deno 提供了腳本安裝器 deno install 讓使用者可以產生一個可執行腳本,簡單的範例如下:

deno install --allow-net --allow-read https://deno.land/std@0.73.0/http/file_server.ts

下完該命令後, Deno 會自動將該模組以及它的依賴模組快取到本地端:

Download https://deno.land/std@0.73.0/http/file_server.ts
Download https://deno.land/std@0.73.0/path/mod.ts
Download https://deno.land/std@0.73.0/http/server.ts
Download https://deno.land/std@0.73.0/flags/mod.ts
Download https://deno.land/std@0.73.0/_util/assert.ts
Download https://deno.land/std@0.73.0/path/_constants.ts
Download https://deno.land/std@0.73.0/path/win32.ts
Download https://deno.land/std@0.73.0/path/posix.ts
Download https://deno.land/std@0.73.0/path/common.ts
Download https://deno.land/std@0.73.0/path/separator.ts
Download https://deno.land/std@0.73.0/path/_interface.ts
Download https://deno.land/std@0.73.0/path/glob.ts
Download https://deno.land/std@0.73.0/encoding/utf8.ts
Download https://deno.land/std@0.73.0/io/bufio.ts
Download https://deno.land/std@0.73.0/async/mod.ts
Download https://deno.land/std@0.73.0/http/_io.ts
Download https://deno.land/std@0.73.0/path/_util.ts
Download https://deno.land/std@0.73.0/textproto/mod.ts
Download https://deno.land/std@0.73.0/http/http_status.ts
Download https://deno.land/std@0.73.0/bytes/mod.ts
Download https://deno.land/std@0.73.0/async/deferred.ts
Download https://deno.land/std@0.73.0/async/delay.ts
Download https://deno.land/std@0.73.0/async/mux_async_iterator.ts
Download https://deno.land/std@0.73.0/async/pool.ts
✅ Successfully installed file_server
C:\Users\UserName\.deno\bin\file_server.cmd

我們可以在命令列的最後看到,相關腳本已經被放到 C:\Users\UserName\.deno\bin\ 的路徑中:

% generated by deno install %
@deno.exe "run" "--allow-read" "--allow-net" "C:\Users\eric\.deno\bin\file_server.js" %*

自訂腳本檔名

我們可以使用 -n/--name 指定腳本名稱:

deno install --allow-net --allow-read -n serve https://deno.land/std@0.73.0/http/file_server.ts

如此一來,在 Windows 10 環境執行後,我們會得到 serve.cmd 的腳本檔案。

筆者會提到 Windows 10 只是因為我今天是用實驗室的電腦編寫文章跟測試功能,其他作業系統平台同樣適用上面提到的方法唷!

更改安裝目錄

根據上面的範例,其實不難發現, deno 腳本的預設安裝目錄為: .deno/bin/ 。

若我們希望改變腳本的存放目錄,可以使用 --root : (該範例適用 Linux 環境)

deno install --allow-net --allow-read --root /usr/local https://deno.land/std@0.73.0/http/file_server.ts

安裝優先權:

  • --root 選項

  • DENO_INSTALL_ROOT 環境變數

  • $HOME/.deno

Previous程式碼打包工具Next程式碼格式化

Last updated 4 years ago

Was this helpful?