On this page

🌐 Tools

Node.js 是在你的机器上执行 JavaScript 的运行时。它将 V8 JavaScript 引擎 与一组内置模块打包在一起,使你可以在浏览器外运行 JavaScript。

Node.js 下载页面 下载适合你平台的安装程序。**LTS(长期支持)**版本是最稳定的选择,建议用于插件开发。安装程序包含 npm。

🌐 Download the appropriate installer for your platform from the Node.js downloads page. The LTS (Long Term Support) release is the most stable choice and is recommended for addon development. The installer includes npm.

Node-API 在所有当前受支持的 Node.js 版本中都是稳定的。任何处于活跃 LTS 或维护 LTS 的版本都可以使用。

npm 是 Node.js 的包管理器。它随 Node.js 一起安装。对于大多数 Node-API 开发者来说,目标是发布一个 npm 包,将 C/C++ 库封装起来,并使其可供 JavaScript 用户使用。

npm 包含在 Node.js 中。你可以通过以下方式保持其更新:

🌐 npm is included with Node.js. You can keep it up to date with:

Git 对于 Node-API 工作并不是严格必需的,但它在整个生态系统中都有使用。大多数示例仓库和依赖安装都依赖它。

🌐 C/C++ compiler and Python

除了 Node 和 npm,你还需要一个 C/C++ 编译器工具链和 Python(node-gyp 所需)。

🌐 In addition to Node and npm, you need a C/C++ compiler toolchain and Python (required by node-gyp.

🌐 Windows

推荐的方法是安装 Visual Studio Build Tools,并选择 “使用 C++ 的桌面开发” 工作负载。这将提供 MSVC 编译器、Windows SDK 以及 node-gyp 所需的构建基础设施。

🌐 The recommended approach is to install Visual Studio Build Tools with the "Desktop development with C++" workload selected. This provides the MSVC compiler, Windows SDK, and the build infrastructure node-gyp requires.

或者,你可以通过 winget 安装:

🌐 Alternatively, you can install via winget:

在安装期间或之后,打开 Visual Studio 安装程序,并确保选中 “使用 C++ 的桌面开发” 工作负载。

🌐 During or after installation, open Visual Studio Installer and ensure the "Desktop development with C++" workload is checked.

还需要安装 Python 3。可以从 python.org 安装,或通过 winget 安装:

🌐 Python 3 is also required. Install it from python.org or via winget:

安装全局工具时,以 管理员 身份运行 PowerShell 或 cmd.exe

安装苹果的命令行开发者工具。如果你还没有安装 Xcode,最快的方式是:

🌐 Install Apple's command-line developer tools. If you haven't installed Xcode already, the quickest route is:

如果那失败了,从 Mac 应用商店安装完整的 Xcode IDE,其中包括必要的编译器工具链。

🌐 If that fails, install the full Xcode IDE from the Mac App Store, which includes the necessary compiler toolchain.

Python 3 随现代 macOS 打包提供。使用 Homebrew 安装它:

🌐 Python 3 is not bundled with modern macOS. Install it using Homebrew:

或者从 python.org 下载安装程序。

🌐 Or download an installer from python.org.

在大多数 Linux 发行版中,所需的 C/C++ 工具链和 Python 要么预装,要么可以很容易地添加。对于基于 Debian/Ubuntu 的系统:

🌐 On most Linux distributions the required C/C++ toolchain and Python are either pre-installed or easily added. For Debian/Ubuntu-based systems:

sudo apt-get update
sudo apt-get install -y build-essential python3

对于其他发行版,请参阅你的包管理器文档或LLVM 安装指南

🌐 For other distributions, refer to your package manager's documentation or the LLVM installation guide.

🌐 Verifying your tools

安装后,验证每个工具是否在你的 PATH 中。

🌐 After installation, verify each tool is on your PATH.

🌐 macOS and Linux

node --version
npm --version
python3 --version
git --version
cc --version
make --version

🌐 Windows (PowerShell)

node --version
npm --version
python --version
git --version

要确认 MSVC 编译器是否可用,请打开 开发者命令提示符(随 Visual Studio 构建工具安装)并运行:

🌐 To confirm the MSVC compiler is available, open a Developer Command Prompt (installed with Visual Studio Build Tools) and run:

🌐 Other tools

你需要一个终端——在 macOS/Linux 上使用 Terminal,在 Windows 上使用 PowerShell 或 Windows Terminal。

🌐 You'll need a shell - Terminal on macOS/Linux, PowerShell or Windows Terminal on Windows.

强烈推荐使用功能强大的代码编辑器。Visual Studio Code 通过 C/C++ 扩展 对 C/C++ 提供了出色的支持,并且可以很好地与 node-gyp 构建集成。CLion 是另一个受欢迎的 C++ 开发选择。

🌐 A capable code editor is strongly recommended. Visual Studio Code has excellent C/C++ support via the C/C++ extension and integrates well with node-gyp builds. CLion is another popular choice for C++ development.