> For the complete documentation index, see [llms.txt](https://developer.eagle.cool/plugin-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.eagle.cool/plugin-api/zh-tw/tutorial/node-js-native-api.md).

# 使用 Node.js 原生 API

Eagle 插件支援使用 Node.js 的原生 API，因此我們可以享受到以下好處：

* 可以利用 Node.js 的強大功能來完成一些複雜的功能，比如數據處理、檔案壓縮、網路通信等。
* 可以使用現有的 Node.js 生態系統中的各種模組和庫來快速完成應用程式的各種功能，避免重複造輪子。
* 可以構建跨平台的應用程式，因為 Node.js 在 Windows、macOS 都有很好的支援。

## 範例 <a href="#oedfw" id="oedfw"></a>

```javascript
const fs = require('fs');

// 讀取檔案
fs.readFile('/path/to/file.txt', (err, data) => {
    if (err) throw err;
    console.log(data);
});

// 寫入檔案
fs.writeFile('/path/to/file.txt', 'Hello, world!', (err) => {
    if (err) throw err;
    console.log('The file has been saved!');
});

```

這段程式碼會讀取一個檔案，然後在檔案中寫入一段文字。在讀取和寫入操作完成時，會在控制枱中輸出相應的資訊。

除了 `fs` 模組外，Node.js 原生 API 還有許多實用的模組提供了一系列常用的功能。下面是一些常用的 Node.js 原生模組：

1. `http` 模組：提供了 HTTP 伺服器和客户端的功能。
2. `path` 模組：提供了處理檔案路徑的工具函式。
3. `os` 模組：提供了取得作業系統資訊的功能。
4. `crypto` 模組：提供了加密和解密的功能。
5. `zlib` 模組：提供了數據壓縮和解壓縮的功能。

## 推薦學習資源 <a href="#unfm7" id="unfm7"></a>

透過使用 Node.js 的原生 API，可以大大提升應用程式的靈活性和功能性。如果您是 Node.js 的新手，那麼下面這些教程可能會對您有所幫助：

* MDN 的 Node.js 入門教程：<https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/Introduction>
* Traversy Media 的《Node.js Tutorial for Beginners》：<https://www.youtube.com/watch?v=TlB_eWDSMt4>
* freeCodeCamp 的《Node.js Basics Tutorial | Learn the Basics of Node.js in 30 Minutes》：<https://www.youtube.com/watch?v=w-7RQ46RgxU>
* The Net Ninja 的《Node.js Tutorial for Beginners》：<https://www.youtube.com/watch?v=w-7RQ46RgxU>

上面這些影片可以幫助您快速入門 Node.js 開發，瞭解 Node.js 的基礎知識和實用技巧。
