{"_path":"/docs/env/backend","_draft":false,"_partial":false,"_empty":false,"title":"后端开发环境","description":"Node.js 是宁皓独立开发者训练营选择使用的后端技术，我们会基于 Node.js 开发应用的后端（服务端）。","excerpt":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"后端服务端应用开发环境"},"children":[{"type":"text","value":"后端（服务端）应用开发环境"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Node.js 是宁皓独立开发者训练营选择使用的后端技术，我们会基于 Node.js 开发应用的后端（服务端）。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"先在本地电脑上安装一个 Node.js，然后再准备一下应用需要的数据服务，我们为应用选择的是 MySQL 这种数据库。还需要一些必要的客户端软件，比如调试应用接口用的 HTTP 客户端，在训练营中使用的是 Insomnia，还有连接管理数据服务用的数据库客户端，训练营中使用的是 TablePlus。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"准备好这些东西，做一些基本的配置以后，就算是准备好了后端应用开发环境，也就可以开启后端应用开发之旅了。"}]},{"type":"element","tag":"h2","props":{"id":"nodejs"},"children":[{"type":"text","value":"Node.js"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在本地电脑上安装了 Node.js 以后，就可以编写与运行 Node.js 应用了。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://nodejs.org/en/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://nodejs.org/en/"}]}]},{"type":"element","tag":"h3","props":{"id":"安装-nodejs"},"children":[{"type":"text","value":"安装 Node.js"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"到 Node.js 的官方网站，下载 LTS（长期支持） 版本的 Node.js，将其安装在电脑上，完成以后电脑就可以运行 Node.js 应用了。在训练营中开发的应用可在 v16 版本的 Node.js 里运行。"}]},{"type":"element","tag":"h3","props":{"id":"命令行工具"},"children":[{"type":"text","value":"命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在开发 Node.js 应用时，经常需要用到一些命令行工具，这些工具一般就是在 Node.js 软件包（package）里提供的。"}]},{"type":"element","tag":"h4","props":{"id":"全局命令行工具"},"children":[{"type":"text","value":"全局命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"有些命令行工具可以在全局范围安装，比如 Vue 或 Nest 框架提供的命令行工具，就适合将其安装在全局范围，这样就可以在任何地方使用这些工具。执行 npm install 命令的时候，配合使用 global 或 g 选项可以在全局范围安装 Node.js 软件包。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"npm install @vue/cli --global\ncd ~/desktop\nvue create nid-vue\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"npm install @vue/cli --global\ncd ~/desktop\nvue create nid-vue\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在全局范围安装了 Vue 框架的命令行工具以后，进入到桌面，然后执行 vue create 命令，这会在桌面上创建一个 Vue 项目，放在 nid-vue 这个目录里。"}]},{"type":"element","tag":"h4","props":{"id":"项目本地命令行工具"},"children":[{"type":"text","value":"项目本地命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"有些带命令行的软件包需要将其安装在项目本地，比如在 TypeScript 这个包里面提供了一个 tsc 命令，这个包就需要安装在项目本地，因为每个项目需要的软件包的版本可能是不一样的。这种命令行工具软件包或者附带命令行工具的软件包，一般会作为项目的开发依赖，执行 npm install 命令的时候，配合使用 save-dev 或 D 选项可以将软件包作为项目的开发依赖。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"cd ~/desktop/nid-node\nnpm install typescript --save-dev\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"cd ~/desktop/nid-node\nnpm install typescript --save-dev\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"先进入到项目所在目录，然后用 npm install 命令安装一个 typescript 软件包，用 save-dev 选项会将这个软件包作为项目的开发依赖。完成以后可以查看项目里的 node_modules/.bin 这个目录，在里面应该能找到 tsc 这个命令行工具。"}]},{"type":"element","tag":"h4","props":{"id":"执行项目本地命令行工具"},"children":[{"type":"text","value":"执行项目本地命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果安装的软件包里带命令行工具，这些命令行工具一般都会放在项目的 node_modules/.bin 这个目录里。比如你想执行 typescript 这个软件包里带的 tsc 命令，需要指定这个命令行的具体位置，这个位置可以是相对的位置。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"cd ~/desktop/nid-node\n./node_modules/.bin/tsc\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"cd ~/desktop/nid-node\n./node_modules/.bin/tsc\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"确定当前是在项目所在目录的下面，再执行一下给项目安装的 typescript 软件包里带的 tsc 这个命令，也就是当前目录下的 node_modules/.bin 这个目录里的 tsc。"}]},{"type":"element","tag":"h4","props":{"id":"配置-path-环境变量"},"children":[{"type":"text","value":"配置 PATH 环境变量"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果你想在项目里直接执行在安装的软件包里提供的命令行工具，可以配置一下 PATH 这个环境变量，将 ./node_modules/.bin 这个路径添加到 PATH 里。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"*Windows"}]},{"type":"text","value":"：cmder/config/user_profile.sh*"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"macOS"}]},{"type":"text","value":": ~/.zprofile"}]}]},{"type":"element","tag":"code","props":{"code":"export PATH=$PATH:./node_modules/.bin\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"export PATH=$PATH:./node_modules/.bin\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在终端的配置文件里添加上面这行代码，意思就是在 PATH 这个环境变量里添加 ./node_modules/.bin 这个路径，这样在项目所在目录的下面执行命令的时候，终端会在这个路径里查找要执行的命令行工具，也就不需要我们再输入命令的具体位置了。"}]},{"type":"element","tag":"blockquote","props":{},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"修改了终端的配置文件以后，要重启终端，这样新做的配置才能生效。"}]}]},{"type":"element","tag":"h3","props":{"id":"软件包的安装源"},"children":[{"type":"text","value":"软件包的安装源"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"基于 Node.js 开发应用时，需要安装一些第三方提供的软件包（package），这些东西默认来自 npm 网站，如果你发现安装软件包时速度很慢，可以考虑切换使用第三方提供的安装源。"}]},{"type":"element","tag":"h4","props":{"id":"使用-nrm-管理软件包的安装源"},"children":[{"type":"text","value":"使用 nrm 管理软件包的安装源"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"借助 nrm 这个命令行工具可以方便地切换不同的安装源。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"安装 nrm 命令行工具"}]}]},{"type":"element","tag":"code","props":{"code":"npm install nrm --global\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"npm install nrm --global\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在全局范围安装 nrm 这个命令行工具。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"列出可用安装源"}]}]},{"type":"element","tag":"code","props":{"code":"nrm ls\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nrm ls\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"返回的结果："}]},{"type":"element","tag":"code","props":{"code":"* npm -------- https://registry.npmjs.org/\n  yarn ------- https://registry.yarnpkg.com/\n  cnpm ------- http://r.cnpmjs.org/\n  taobao ----- https://registry.npm.taobao.org/\n  ...\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"* npm -------- https://registry.npmjs.org/\n  yarn ------- https://registry.yarnpkg.com/\n  cnpm ------- http://r.cnpmjs.org/\n  taobao ----- https://registry.npm.taobao.org/\n  ...\n"}]}]}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"号标注的就是当前使用的软件包安装源，默认就是 npm。"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"切换安装源"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在国内可以选择使用 taobao 这个安装源。"}]},{"type":"element","tag":"code","props":{"code":"nrm use taobao\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nrm use taobao\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面这行命令会将安装源设置成 taobao，这时再执行 nrm ls 查看安装源列表，你会发现 taobao 会变成当前使用的安装源。将软件包的安装源切换至第三方以后，如果你想把自己编写的软件包发布到 npm，需要将安装源切换回 npm。"}]},{"type":"element","tag":"h3","props":{"id":"多版本-nodejs可选"},"children":[{"type":"text","value":"多版本 Node.js（可选）"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"默认在操作系统里只能存在一个版本的 Node.js，有时我们可能需要根据不同的 Node.js 项目，使用不同版本的 Node.js，可以借助一些工具（nvm），在系统里同时安装多个版本的 Node.js，通过项目的配置或者使用命令可以切换使用不同版本的 Node.js。macOS 用户可以使用 nvm，Windows 用户可以使用 NVM for Windows。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果在系统里安装了多个版本的 Node.js，切换使用不同版本的 Node.js 以后，需要重新安装在全局范围里安装的命令行工具。"}]},{"type":"element","tag":"h4","props":{"id":"nvm"},"children":[{"type":"text","value":"nvm"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"nvm 这个工具允许在系统上同时存在多个版本的 Node.js，推荐 macOS 用户使用这个工具来管理安装在系统里的 Node.js，这样可以任意切换使用需要的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"项目地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://github.com/nvm-sh/nvm","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://github.com/nvm-sh/nvm"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"安装 nvm 命令行工具"}]}]},{"type":"element","tag":"code","props":{"code":"sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在终端，执行上面这行命令会在系统里安装好 nvm 这个命令行工具。首先会下载 install.sh 这个脚本文件，里面写的就是安装 nvm 需要做的一些事情，这个文件是在 github 上提供的，所以在国内有可能会遇到无法连接的问题，在系统网络的 DNS 里添加 8.8.8.8 这个地址应该可以解决问题。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"完成安装以后，需要重新启动终端，这样就可以在终端使用 nvm 这个命令了。nvm 的安装脚本会修改终端的配置文件，比如 ~/.zshrc，你可以查看一下这个文件的内容，应该会看到类似下面这样的内容："}]},{"type":"element","tag":"code","props":{"code":"export NVM_DIR=\"$HOME/.nvm\"\n...\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"export NVM_DIR=\"$HOME/.nvm\"\n...\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"安装指定版本的 Node.js"}]}]},{"type":"element","tag":"code","props":{"code":"nvm install 16.15.0\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm install 16.15.0\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面的命令可以安装 16.15.0 版本的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"查看所有可用的版本"}]}]},{"type":"element","tag":"code","props":{"code":"nvm ls-remote\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm ls-remote\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面这行命令会列出所有可以安装使用的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"查看已经安装的版本"}]}]},{"type":"element","tag":"code","props":{"code":"nvm ls\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm ls\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面这行命令会列出当前已经安装在系统上的 Node.js，还会显示当前正在使用的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"设置当前使用的版本"}]}]},{"type":"element","tag":"code","props":{"code":"nvm use 16.15.0\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm use 16.15.0\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面的命令会将当前使用的 Node.js 设置成 16.15.0 这个版本。"}]},{"type":"element","tag":"h4","props":{"id":"nvm-for-windows"},"children":[{"type":"text","value":"NVM for Windows"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"项目地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://github.com/coreybutler/nvm-windows","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://github.com/coreybutler/nvm-windows"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"NVM for Windows 跟上面介绍的 nvm 差不多，但不是同一个项目。Windows 用户可以使用 NVM for Windows，它提供了一个安装包，下载并将其安装在电脑上，打开终端以后，就可以使用 nvm 这个命令了。"}]},{"type":"element","tag":"h3","props":{"id":"软件包编译环境"},"children":[{"type":"text","value":"软件包编译环境"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"开发 Node.js 应用会为项目安装一些软件包，大部分软件包直接就可以使用，不过有些软件包需要编译成本地的 Node 模块，这就需要我们的系统拥有合适的编译环境。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在宁皓独立开发者训练营基于 Node.js 开发后端应用时，会用到一个 bcrypt 这个软件包，为项目安装它的时候就有可能需要编译本地模块。如果在安装过程中出现类似 node-pre-gyp ERR! build error 这些的句子，说明编译本地模块的时候出了问题，也就是我们的系统暂时无法满足编译条件。"}]},{"type":"element","tag":"h4","props":{"id":"macos安装-xcode"},"children":[{"type":"text","value":"macOS：安装 XCode"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image.png"},"children":[]},{"type":"text","value":"\n在 macOS 系统中安装 XCode 这个软件以后就支持 Node.js 编译本地模块了，在 App Store 里搜索并安装 XCode，完成以后打开这个软件，应该会提示你安装一些额外的组件或者一些命令行工具，确定安装这些东西。"}]},{"type":"element","tag":"h4","props":{"id":"windows安装编译工具"},"children":[{"type":"text","value":"Windows：安装编译工具"}]},{"type":"element","tag":"code","props":{"code":"npm install --global windows-build-tools\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"npm install --global windows-build-tools\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Windows 用户可以在全局范围安装 windows-build-tools，这会在 Windows 系统中准备好编译 Node 本地模块需要的环境。"}]},{"type":"element","tag":"h2","props":{"id":"mysql"},"children":[{"type":"text","value":"MySQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在宁皓独立开发者训练营中，我们会用 MySQL 为应用提供数据服务。在本地电脑上安装并运行一个 MySQL 服务器（8.x），这样服务端应用就可以连接使用这个数据服务，管理应用的数据了。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://www.mysql.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://www.mysql.com/"}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"下载地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://dev.mysql.com/downloads/mysql/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://dev.mysql.com/downloads/mysql/"}]}]}]},{"type":"element","tag":"h3","props":{"id":"macos安装-mysql"},"children":[{"type":"text","value":"macOS：安装 MySQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 MySQL 的官方网站，选择下载 8.x 社区版的 MySQL。打开下载页面以后，Select Operating System 选择 macOS。根据电脑架构选择合适的版本，如果电脑用的是 m1 芯片，可以下载 ARM 版本，如果是 intel 处理器，可以下载 x86 版本。在系统的 "},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"关于电脑"}]},{"type":"text","value":" 那里可以查看电脑使用的处理器。无论是哪种版本，推荐下载用 DMG 格式封闭的 MySQL，下载完成以后将其安装在系统里。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(1).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"macos管理-mysql-服务"},"children":[{"type":"text","value":"macOS：管理 MySQL 服务"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 macOS 系统里安装了 MySQL 服务器以后，在系统的偏好设置那里可以找到 MySQL 服务的管理界面，在这里可以管理 MySQL 服务器，比如停止或启动 MySQL 服务。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(2).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"windows安装-mysql"},"children":[{"type":"text","value":"Windows：安装 MySQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 MySQL 的官方网站，选择下载 8.x 社区版的 MySQL。打开下载页面以后，Select Operating System 选择 Microsoft Windows，然后点击 MySQL Installer for Windows，下载带安装向导的 MySQL（如 mysql-installer-community-8.0.29.0.msi），然后将其安装在系统里。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(3).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"windows管理-mysql-服务"},"children":[{"type":"text","value":"Windows：管理 MySQL 服务"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 Windows 系统里安装了 MySQL 服务器以后，在系统托盘那里应该会出现一个 MySQL 小图标，通过它可以管理 MySQL 服务的启动状态。"}]},{"type":"element","tag":"h3","props":{"id":"root-用户"},"children":[{"type":"text","value":"root 用户"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"MySQL 里的 root 用户是超级管理员，拥有管理整个服务的权限，比如管理数据库与用户等等。在安装 MySQL 的过程中，应该会提示你设置这个用户的密码，稍后我们会用到这个用户与给他设置的密码连接管理 MySQL 服务。"}]},{"type":"element","tag":"h2","props":{"id":"tableplus"},"children":[{"type":"text","value":"TablePlus"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"TablePlus 是一种数据库客户端软件，用它可以连接管理不同类型的数据服务。在训练营中我们会使用 TablePlus 连接管理 MySQL 数据服务，观察应用数据仓库里的数据与结构，练习 SQL 语言等等。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://tableplus.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://tableplus.com/"}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"下载地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://tableplus.com/download","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://tableplus.com/download"}]}]}]},{"type":"element","tag":"h3","props":{"id":"连接-mysql-服务"},"children":[{"type":"text","value":"连接 MySQL 服务"}]},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"打开 TablePlus。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击界面底部的 Create a new connection...（创建新连接）。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"数据服务的类型选择 MySQL，然后点击 Create。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"配置连接。"},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Name：随便填写一个连接名称。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Ver.：版本设置成 Default。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Host：数据服务在本地，所以主机名设置成 127.0.0.1。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Port：MySQL 服务默认的端口号是 3306。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"User：可以填写 root。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Password：输入 root 用户的密码。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Database：连接的数据仓库的名字，暂时没有可以留空。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击 Test，测试连接，一切正常的话文本框会变绿，测试失败会出现提示。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击 Connect 确定打开连接。"}]}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(4).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"创建新连接，选择数据服务类型"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(5).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"连接的配置界面"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(6).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"打开连接后显示的界面"}]}]},{"type":"element","tag":"h3","props":{"id":"创建数据仓库"},"children":[{"type":"text","value":"创建数据仓库"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开之前创建的连接以后，需要再打开数据服务里的一个具体的数据仓库。点击界面标题栏上的数据仓库小图标（在 SQL 左边），这会打开 Open database 窗口，在这里会列出当前连接可以管理的数据仓库，点击 + 号小图标会显示 New Database 窗口。"}]},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Name：数据仓库名字，比如 xb2_node。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Encoding：数据编码格式，选择 utf8mb4。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Collation：数据整理，选择 utf8mb4_0900_ai_ci。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击 OK，确定创建新的数据仓库。"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(7).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 创建数据仓库"}]}]},{"type":"element","tag":"h3","props":{"id":"打开数据仓库"},"children":[{"type":"text","value":"打开数据仓库"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"创建了数据仓库以后，可以在 Open database 这里列出这个新的数据仓库，选中并打开它。每次打开连接以后，都需要打开需要管理的数据仓库。我们可以编辑一下之前创建的连接，在 Database 那里输入连接以后要打开的数据仓库的名字，比如 xb2_node，这样打开连接的同时会打开 xb2_node 这个数据仓库。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(8).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 打开数据仓库"}]}]},{"type":"element","tag":"h3","props":{"id":"管理数据仓库"},"children":[{"type":"text","value":"管理数据仓库"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开连接并打开了数据仓库以后，如果数据仓库里拥有已经创建的数据表（Tables），在左边栏就会显示这些数据表。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"观察数据记录"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"选中某个数据表，在右边会显示这个数据表里的数据记录。调试服务端应用的时候，经常需要在 TablePlus 里观察数据表里的数据的变化，刷新（command + R） TablePlus 应用的界面可以查看最新的变化。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(9).png"},"children":[]},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"修改数据记录"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 TablePlus 里可以直接修改数据表里的数据记录的值，也可以添加新的数据记录或者删除数据记录，确定这些操作需要保存（command + S）。被修改的数据记录与数据表会用特殊颜色标记，确定保存以后会变成正常状态。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(10).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 会使用特殊颜色标记被修改的数据记录与数据表了数据记录"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"数据表结构"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开数据表以后，默认会显示数据表里的 Data（数据），点击界面底部的 Structure（结构）可以查看与修改数据表的结构，修改了数据表的结构以后，需要保存（command + S）才能生效。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(11).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 提供的数据表结构的管理界面"}]}]},{"type":"element","tag":"h3","props":{"id":"执行-sql"},"children":[{"type":"text","value":"执行 SQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"点击界面顶部的标题栏里的 SQL 图标，可以打开执行 SQL 的界面，在这里可以通过执行 SQL 操作数据仓库，界面下方会显示执行的结果或查询出来的数据。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(12).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 提供的 SQL 界面"}]}]},{"type":"element","tag":"h2","props":{"id":"insomnia"},"children":[{"type":"text","value":"Insomnia"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Insomnia 是一种 Http 客户端软件，我们在训练营中开发应用时，在测试与调试服务端应用接口的时候会用到它。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://insomnia.rest/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://insomnia.rest"}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"下载地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://insomnia.rest/download","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://insomnia.rest/download"}]}]}]},{"type":"element","tag":"h3","props":{"id":"管理项目"},"children":[{"type":"text","value":"管理项目"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开 Insomnia 以后可以先创建一个 project（项目），每个项目的下面可以拥有属于自己的一些接口的设计文档（design document）或是请求集合（request collection）。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(13).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"请求集合"},"children":[{"type":"text","value":"请求集合"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在项目下面，点击 Create 按钮，在弹出的菜单里选择 Request Collection，创建一个请求集合，每个请求集合里面可以包含一组请求。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(14).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"管理环境"},"children":[{"type":"text","value":"管理环境"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开创建的请求集合，可以管理一下在这个集合里的环境。每个环境里都可以设置一些环境变量，在创建请求的时候可以使用这些环境变量。切换集合当前使用的环境，这些环境变量的值也会发生相应的变化。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"比如我们在请求集合里创建两个环境：开发环境与生产环境，在这两个环境里面定义一个名字是 nid_nest_api 的环境变量，它的值就是服务端应用在不同环境下的基本地址。这样如果在请求里使用了 nid_nest_api 这个环境变量，就可以得到服务端接口的基本地址了，而且在切换集合当前环境的时候，这个地址也会发生改变。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(15).png"},"children":[]},{"type":"text","value":"\n点击环境名称会弹出菜单，列出当前可用的环境，点击 Manage Environments，可以管理集合的环境，在 Sub Environments 下面新建两个环境，然后分别设置一些环境变量，数据的格式是 JSON。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(16).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"图中显示在开发环境中添加了一个 nid_nest_api，对应的值是 "},{"type":"element","tag":"a","props":{"href":"http://localhost:3000/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://localhost:3000"}]},{"type":"text","value":"。"}]}]},{"type":"element","tag":"h3","props":{"id":"管理请求"},"children":[{"type":"text","value":"管理请求"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开请求集合以后，可以创建一些 Folder（目录），然后在这些目录里再分别创建一些 Request（请求）。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(17).png"},"children":[]},{"type":"text","value":"\n在请求中可以使用请求集合里创建的环境里定义的环境变量，比如在上图这个 "},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"创建内容"}]},{"type":"text","value":" 请求中，请求的地址里用了 nid_nest_api 这个环境变量，当前这个请求集合设置使用的环境是 "},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"开发环境"}]},{"type":"text","value":"，所以这个环境变量的值就是在开发环境里定义的 nid_nest_api 的值，也就是 "},{"type":"element","tag":"a","props":{"href":"http://localhost/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://localhost"}]},{"type":"text","value":":3000。"}]}]},"body":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"后端服务端应用开发环境"},"children":[{"type":"text","value":"后端（服务端）应用开发环境"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Node.js 是宁皓独立开发者训练营选择使用的后端技术，我们会基于 Node.js 开发应用的后端（服务端）。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"先在本地电脑上安装一个 Node.js，然后再准备一下应用需要的数据服务，我们为应用选择的是 MySQL 这种数据库。还需要一些必要的客户端软件，比如调试应用接口用的 HTTP 客户端，在训练营中使用的是 Insomnia，还有连接管理数据服务用的数据库客户端，训练营中使用的是 TablePlus。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"准备好这些东西，做一些基本的配置以后，就算是准备好了后端应用开发环境，也就可以开启后端应用开发之旅了。"}]},{"type":"element","tag":"h2","props":{"id":"nodejs"},"children":[{"type":"text","value":"Node.js"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在本地电脑上安装了 Node.js 以后，就可以编写与运行 Node.js 应用了。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://nodejs.org/en/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://nodejs.org/en/"}]}]},{"type":"element","tag":"h3","props":{"id":"安装-nodejs"},"children":[{"type":"text","value":"安装 Node.js"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"到 Node.js 的官方网站，下载 LTS（长期支持） 版本的 Node.js，将其安装在电脑上，完成以后电脑就可以运行 Node.js 应用了。在训练营中开发的应用可在 v16 版本的 Node.js 里运行。"}]},{"type":"element","tag":"h3","props":{"id":"命令行工具"},"children":[{"type":"text","value":"命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在开发 Node.js 应用时，经常需要用到一些命令行工具，这些工具一般就是在 Node.js 软件包（package）里提供的。"}]},{"type":"element","tag":"h4","props":{"id":"全局命令行工具"},"children":[{"type":"text","value":"全局命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"有些命令行工具可以在全局范围安装，比如 Vue 或 Nest 框架提供的命令行工具，就适合将其安装在全局范围，这样就可以在任何地方使用这些工具。执行 npm install 命令的时候，配合使用 global 或 g 选项可以在全局范围安装 Node.js 软件包。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"npm install @vue/cli --global\ncd ~/desktop\nvue create nid-vue\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"npm install @vue/cli --global\ncd ~/desktop\nvue create nid-vue\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在全局范围安装了 Vue 框架的命令行工具以后，进入到桌面，然后执行 vue create 命令，这会在桌面上创建一个 Vue 项目，放在 nid-vue 这个目录里。"}]},{"type":"element","tag":"h4","props":{"id":"项目本地命令行工具"},"children":[{"type":"text","value":"项目本地命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"有些带命令行的软件包需要将其安装在项目本地，比如在 TypeScript 这个包里面提供了一个 tsc 命令，这个包就需要安装在项目本地，因为每个项目需要的软件包的版本可能是不一样的。这种命令行工具软件包或者附带命令行工具的软件包，一般会作为项目的开发依赖，执行 npm install 命令的时候，配合使用 save-dev 或 D 选项可以将软件包作为项目的开发依赖。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"cd ~/desktop/nid-node\nnpm install typescript --save-dev\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"cd ~/desktop/nid-node\nnpm install typescript --save-dev\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"先进入到项目所在目录，然后用 npm install 命令安装一个 typescript 软件包，用 save-dev 选项会将这个软件包作为项目的开发依赖。完成以后可以查看项目里的 node_modules/.bin 这个目录，在里面应该能找到 tsc 这个命令行工具。"}]},{"type":"element","tag":"h4","props":{"id":"执行项目本地命令行工具"},"children":[{"type":"text","value":"执行项目本地命令行工具"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果安装的软件包里带命令行工具，这些命令行工具一般都会放在项目的 node_modules/.bin 这个目录里。比如你想执行 typescript 这个软件包里带的 tsc 命令，需要指定这个命令行的具体位置，这个位置可以是相对的位置。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"示例"}]}]},{"type":"element","tag":"code","props":{"code":"cd ~/desktop/nid-node\n./node_modules/.bin/tsc\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"cd ~/desktop/nid-node\n./node_modules/.bin/tsc\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"确定当前是在项目所在目录的下面，再执行一下给项目安装的 typescript 软件包里带的 tsc 这个命令，也就是当前目录下的 node_modules/.bin 这个目录里的 tsc。"}]},{"type":"element","tag":"h4","props":{"id":"配置-path-环境变量"},"children":[{"type":"text","value":"配置 PATH 环境变量"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果你想在项目里直接执行在安装的软件包里提供的命令行工具，可以配置一下 PATH 这个环境变量，将 ./node_modules/.bin 这个路径添加到 PATH 里。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"*Windows"}]},{"type":"text","value":"：cmder/config/user_profile.sh*"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"macOS"}]},{"type":"text","value":": ~/.zprofile"}]}]},{"type":"element","tag":"code","props":{"code":"export PATH=$PATH:./node_modules/.bin\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"export PATH=$PATH:./node_modules/.bin\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在终端的配置文件里添加上面这行代码，意思就是在 PATH 这个环境变量里添加 ./node_modules/.bin 这个路径，这样在项目所在目录的下面执行命令的时候，终端会在这个路径里查找要执行的命令行工具，也就不需要我们再输入命令的具体位置了。"}]},{"type":"element","tag":"blockquote","props":{},"children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"修改了终端的配置文件以后，要重启终端，这样新做的配置才能生效。"}]}]},{"type":"element","tag":"h3","props":{"id":"软件包的安装源"},"children":[{"type":"text","value":"软件包的安装源"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"基于 Node.js 开发应用时，需要安装一些第三方提供的软件包（package），这些东西默认来自 npm 网站，如果你发现安装软件包时速度很慢，可以考虑切换使用第三方提供的安装源。"}]},{"type":"element","tag":"h4","props":{"id":"使用-nrm-管理软件包的安装源"},"children":[{"type":"text","value":"使用 nrm 管理软件包的安装源"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"借助 nrm 这个命令行工具可以方便地切换不同的安装源。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"安装 nrm 命令行工具"}]}]},{"type":"element","tag":"code","props":{"code":"npm install nrm --global\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"npm install nrm --global\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在全局范围安装 nrm 这个命令行工具。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"列出可用安装源"}]}]},{"type":"element","tag":"code","props":{"code":"nrm ls\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nrm ls\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"返回的结果："}]},{"type":"element","tag":"code","props":{"code":"* npm -------- https://registry.npmjs.org/\n  yarn ------- https://registry.yarnpkg.com/\n  cnpm ------- http://r.cnpmjs.org/\n  taobao ----- https://registry.npm.taobao.org/\n  ...\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"* npm -------- https://registry.npmjs.org/\n  yarn ------- https://registry.yarnpkg.com/\n  cnpm ------- http://r.cnpmjs.org/\n  taobao ----- https://registry.npm.taobao.org/\n  ...\n"}]}]}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"号标注的就是当前使用的软件包安装源，默认就是 npm。"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"切换安装源"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在国内可以选择使用 taobao 这个安装源。"}]},{"type":"element","tag":"code","props":{"code":"nrm use taobao\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nrm use taobao\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面这行命令会将安装源设置成 taobao，这时再执行 nrm ls 查看安装源列表，你会发现 taobao 会变成当前使用的安装源。将软件包的安装源切换至第三方以后，如果你想把自己编写的软件包发布到 npm，需要将安装源切换回 npm。"}]},{"type":"element","tag":"h3","props":{"id":"多版本-nodejs可选"},"children":[{"type":"text","value":"多版本 Node.js（可选）"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"默认在操作系统里只能存在一个版本的 Node.js，有时我们可能需要根据不同的 Node.js 项目，使用不同版本的 Node.js，可以借助一些工具（nvm），在系统里同时安装多个版本的 Node.js，通过项目的配置或者使用命令可以切换使用不同版本的 Node.js。macOS 用户可以使用 nvm，Windows 用户可以使用 NVM for Windows。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"如果在系统里安装了多个版本的 Node.js，切换使用不同版本的 Node.js 以后，需要重新安装在全局范围里安装的命令行工具。"}]},{"type":"element","tag":"h4","props":{"id":"nvm"},"children":[{"type":"text","value":"nvm"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"nvm 这个工具允许在系统上同时存在多个版本的 Node.js，推荐 macOS 用户使用这个工具来管理安装在系统里的 Node.js，这样可以任意切换使用需要的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"项目地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://github.com/nvm-sh/nvm","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://github.com/nvm-sh/nvm"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"安装 nvm 命令行工具"}]}]},{"type":"element","tag":"code","props":{"code":"sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在终端，执行上面这行命令会在系统里安装好 nvm 这个命令行工具。首先会下载 install.sh 这个脚本文件，里面写的就是安装 nvm 需要做的一些事情，这个文件是在 github 上提供的，所以在国内有可能会遇到无法连接的问题，在系统网络的 DNS 里添加 8.8.8.8 这个地址应该可以解决问题。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"完成安装以后，需要重新启动终端，这样就可以在终端使用 nvm 这个命令了。nvm 的安装脚本会修改终端的配置文件，比如 ~/.zshrc，你可以查看一下这个文件的内容，应该会看到类似下面这样的内容："}]},{"type":"element","tag":"code","props":{"code":"export NVM_DIR=\"$HOME/.nvm\"\n...\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"export NVM_DIR=\"$HOME/.nvm\"\n...\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"安装指定版本的 Node.js"}]}]},{"type":"element","tag":"code","props":{"code":"nvm install 16.15.0\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm install 16.15.0\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面的命令可以安装 16.15.0 版本的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"查看所有可用的版本"}]}]},{"type":"element","tag":"code","props":{"code":"nvm ls-remote\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm ls-remote\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面这行命令会列出所有可以安装使用的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"查看已经安装的版本"}]}]},{"type":"element","tag":"code","props":{"code":"nvm ls\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm ls\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面这行命令会列出当前已经安装在系统上的 Node.js，还会显示当前正在使用的 Node.js。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"设置当前使用的版本"}]}]},{"type":"element","tag":"code","props":{"code":"nvm use 16.15.0\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"nvm use 16.15.0\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"执行上面的命令会将当前使用的 Node.js 设置成 16.15.0 这个版本。"}]},{"type":"element","tag":"h4","props":{"id":"nvm-for-windows"},"children":[{"type":"text","value":"NVM for Windows"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"项目地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://github.com/coreybutler/nvm-windows","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://github.com/coreybutler/nvm-windows"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"NVM for Windows 跟上面介绍的 nvm 差不多，但不是同一个项目。Windows 用户可以使用 NVM for Windows，它提供了一个安装包，下载并将其安装在电脑上，打开终端以后，就可以使用 nvm 这个命令了。"}]},{"type":"element","tag":"h3","props":{"id":"软件包编译环境"},"children":[{"type":"text","value":"软件包编译环境"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"开发 Node.js 应用会为项目安装一些软件包，大部分软件包直接就可以使用，不过有些软件包需要编译成本地的 Node 模块，这就需要我们的系统拥有合适的编译环境。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在宁皓独立开发者训练营基于 Node.js 开发后端应用时，会用到一个 bcrypt 这个软件包，为项目安装它的时候就有可能需要编译本地模块。如果在安装过程中出现类似 node-pre-gyp ERR! build error 这些的句子，说明编译本地模块的时候出了问题，也就是我们的系统暂时无法满足编译条件。"}]},{"type":"element","tag":"h4","props":{"id":"macos安装-xcode"},"children":[{"type":"text","value":"macOS：安装 XCode"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image.png"},"children":[]},{"type":"text","value":"\n在 macOS 系统中安装 XCode 这个软件以后就支持 Node.js 编译本地模块了，在 App Store 里搜索并安装 XCode，完成以后打开这个软件，应该会提示你安装一些额外的组件或者一些命令行工具，确定安装这些东西。"}]},{"type":"element","tag":"h4","props":{"id":"windows安装编译工具"},"children":[{"type":"text","value":"Windows：安装编译工具"}]},{"type":"element","tag":"code","props":{"code":"npm install --global windows-build-tools\n"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"npm install --global windows-build-tools\n"}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Windows 用户可以在全局范围安装 windows-build-tools，这会在 Windows 系统中准备好编译 Node 本地模块需要的环境。"}]},{"type":"element","tag":"h2","props":{"id":"mysql"},"children":[{"type":"text","value":"MySQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在宁皓独立开发者训练营中，我们会用 MySQL 为应用提供数据服务。在本地电脑上安装并运行一个 MySQL 服务器（8.x），这样服务端应用就可以连接使用这个数据服务，管理应用的数据了。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://www.mysql.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://www.mysql.com/"}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"下载地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://dev.mysql.com/downloads/mysql/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://dev.mysql.com/downloads/mysql/"}]}]}]},{"type":"element","tag":"h3","props":{"id":"macos安装-mysql"},"children":[{"type":"text","value":"macOS：安装 MySQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 MySQL 的官方网站，选择下载 8.x 社区版的 MySQL。打开下载页面以后，Select Operating System 选择 macOS。根据电脑架构选择合适的版本，如果电脑用的是 m1 芯片，可以下载 ARM 版本，如果是 intel 处理器，可以下载 x86 版本。在系统的 "},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"关于电脑"}]},{"type":"text","value":" 那里可以查看电脑使用的处理器。无论是哪种版本，推荐下载用 DMG 格式封闭的 MySQL，下载完成以后将其安装在系统里。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(1).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"macos管理-mysql-服务"},"children":[{"type":"text","value":"macOS：管理 MySQL 服务"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 macOS 系统里安装了 MySQL 服务器以后，在系统的偏好设置那里可以找到 MySQL 服务的管理界面，在这里可以管理 MySQL 服务器，比如停止或启动 MySQL 服务。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(2).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"windows安装-mysql"},"children":[{"type":"text","value":"Windows：安装 MySQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 MySQL 的官方网站，选择下载 8.x 社区版的 MySQL。打开下载页面以后，Select Operating System 选择 Microsoft Windows，然后点击 MySQL Installer for Windows，下载带安装向导的 MySQL（如 mysql-installer-community-8.0.29.0.msi），然后将其安装在系统里。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(3).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"windows管理-mysql-服务"},"children":[{"type":"text","value":"Windows：管理 MySQL 服务"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 Windows 系统里安装了 MySQL 服务器以后，在系统托盘那里应该会出现一个 MySQL 小图标，通过它可以管理 MySQL 服务的启动状态。"}]},{"type":"element","tag":"h3","props":{"id":"root-用户"},"children":[{"type":"text","value":"root 用户"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"MySQL 里的 root 用户是超级管理员，拥有管理整个服务的权限，比如管理数据库与用户等等。在安装 MySQL 的过程中，应该会提示你设置这个用户的密码，稍后我们会用到这个用户与给他设置的密码连接管理 MySQL 服务。"}]},{"type":"element","tag":"h2","props":{"id":"tableplus"},"children":[{"type":"text","value":"TablePlus"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"TablePlus 是一种数据库客户端软件，用它可以连接管理不同类型的数据服务。在训练营中我们会使用 TablePlus 连接管理 MySQL 数据服务，观察应用数据仓库里的数据与结构，练习 SQL 语言等等。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://tableplus.com/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://tableplus.com/"}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"下载地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://tableplus.com/download","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://tableplus.com/download"}]}]}]},{"type":"element","tag":"h3","props":{"id":"连接-mysql-服务"},"children":[{"type":"text","value":"连接 MySQL 服务"}]},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"打开 TablePlus。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击界面底部的 Create a new connection...（创建新连接）。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"数据服务的类型选择 MySQL，然后点击 Create。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"配置连接。"},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Name：随便填写一个连接名称。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Ver.：版本设置成 Default。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Host：数据服务在本地，所以主机名设置成 127.0.0.1。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Port：MySQL 服务默认的端口号是 3306。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"User：可以填写 root。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Password：输入 root 用户的密码。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Database：连接的数据仓库的名字，暂时没有可以留空。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击 Test，测试连接，一切正常的话文本框会变绿，测试失败会出现提示。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击 Connect 确定打开连接。"}]}]}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(4).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"创建新连接，选择数据服务类型"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(5).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"连接的配置界面"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(6).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"打开连接后显示的界面"}]}]},{"type":"element","tag":"h3","props":{"id":"创建数据仓库"},"children":[{"type":"text","value":"创建数据仓库"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开之前创建的连接以后，需要再打开数据服务里的一个具体的数据仓库。点击界面标题栏上的数据仓库小图标（在 SQL 左边），这会打开 Open database 窗口，在这里会列出当前连接可以管理的数据仓库，点击 + 号小图标会显示 New Database 窗口。"}]},{"type":"element","tag":"ol","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Name：数据仓库名字，比如 xb2_node。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Encoding：数据编码格式，选择 utf8mb4。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Collation：数据整理，选择 utf8mb4_0900_ai_ci。"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"点击 OK，确定创建新的数据仓库。"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(7).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 创建数据仓库"}]}]},{"type":"element","tag":"h3","props":{"id":"打开数据仓库"},"children":[{"type":"text","value":"打开数据仓库"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"创建了数据仓库以后，可以在 Open database 这里列出这个新的数据仓库，选中并打开它。每次打开连接以后，都需要打开需要管理的数据仓库。我们可以编辑一下之前创建的连接，在 Database 那里输入连接以后要打开的数据仓库的名字，比如 xb2_node，这样打开连接的同时会打开 xb2_node 这个数据仓库。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(8).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 打开数据仓库"}]}]},{"type":"element","tag":"h3","props":{"id":"管理数据仓库"},"children":[{"type":"text","value":"管理数据仓库"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开连接并打开了数据仓库以后，如果数据仓库里拥有已经创建的数据表（Tables），在左边栏就会显示这些数据表。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"观察数据记录"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"选中某个数据表，在右边会显示这个数据表里的数据记录。调试服务端应用的时候，经常需要在 TablePlus 里观察数据表里的数据的变化，刷新（command + R） TablePlus 应用的界面可以查看最新的变化。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(9).png"},"children":[]},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"修改数据记录"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在 TablePlus 里可以直接修改数据表里的数据记录的值，也可以添加新的数据记录或者删除数据记录，确定这些操作需要保存（command + S）。被修改的数据记录与数据表会用特殊颜色标记，确定保存以后会变成正常状态。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(10).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 会使用特殊颜色标记被修改的数据记录与数据表了数据记录"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"数据表结构"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开数据表以后，默认会显示数据表里的 Data（数据），点击界面底部的 Structure（结构）可以查看与修改数据表的结构，修改了数据表的结构以后，需要保存（command + S）才能生效。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(11).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 提供的数据表结构的管理界面"}]}]},{"type":"element","tag":"h3","props":{"id":"执行-sql"},"children":[{"type":"text","value":"执行 SQL"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"点击界面顶部的标题栏里的 SQL 图标，可以打开执行 SQL 的界面，在这里可以通过执行 SQL 操作数据仓库，界面下方会显示执行的结果或查询出来的数据。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(12).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"TablePlus 提供的 SQL 界面"}]}]},{"type":"element","tag":"h2","props":{"id":"insomnia"},"children":[{"type":"text","value":"Insomnia"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Insomnia 是一种 Http 客户端软件，我们在训练营中开发应用时，在测试与调试服务端应用接口的时候会用到它。"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"官方网站"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://insomnia.rest/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://insomnia.rest"}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"下载地址"}]},{"type":"text","value":"："},{"type":"element","tag":"a","props":{"href":"https://insomnia.rest/download","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"https://insomnia.rest/download"}]}]}]},{"type":"element","tag":"h3","props":{"id":"管理项目"},"children":[{"type":"text","value":"管理项目"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开 Insomnia 以后可以先创建一个 project（项目），每个项目的下面可以拥有属于自己的一些接口的设计文档（design document）或是请求集合（request collection）。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(13).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"请求集合"},"children":[{"type":"text","value":"请求集合"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"在项目下面，点击 Create 按钮，在弹出的菜单里选择 Request Collection，创建一个请求集合，每个请求集合里面可以包含一组请求。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(14).png"},"children":[]}]},{"type":"element","tag":"h3","props":{"id":"管理环境"},"children":[{"type":"text","value":"管理环境"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开创建的请求集合，可以管理一下在这个集合里的环境。每个环境里都可以设置一些环境变量，在创建请求的时候可以使用这些环境变量。切换集合当前使用的环境，这些环境变量的值也会发生相应的变化。"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"比如我们在请求集合里创建两个环境：开发环境与生产环境，在这两个环境里面定义一个名字是 nid_nest_api 的环境变量，它的值就是服务端应用在不同环境下的基本地址。这样如果在请求里使用了 nid_nest_api 这个环境变量，就可以得到服务端接口的基本地址了，而且在切换集合当前环境的时候，这个地址也会发生改变。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(15).png"},"children":[]},{"type":"text","value":"\n点击环境名称会弹出菜单，列出当前可用的环境，点击 Manage Environments，可以管理集合的环境，在 Sub Environments 下面新建两个环境，然后分别设置一些环境变量，数据的格式是 JSON。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(16).png"},"children":[]},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"图中显示在开发环境中添加了一个 nid_nest_api，对应的值是 "},{"type":"element","tag":"a","props":{"href":"http://localhost:3000/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://localhost:3000"}]},{"type":"text","value":"。"}]}]},{"type":"element","tag":"h3","props":{"id":"管理请求"},"children":[{"type":"text","value":"管理请求"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"打开请求集合以后，可以创建一些 Folder（目录），然后在这些目录里再分别创建一些 Request（请求）。\n"},{"type":"element","tag":"img","props":{"alt":"","src":"/images/docs/env/backend/image(17).png"},"children":[]},{"type":"text","value":"\n在请求中可以使用请求集合里创建的环境里定义的环境变量，比如在上图这个 "},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"创建内容"}]},{"type":"text","value":" 请求中，请求的地址里用了 nid_nest_api 这个环境变量，当前这个请求集合设置使用的环境是 "},{"type":"element","tag":"em","props":{},"children":[{"type":"text","value":"开发环境"}]},{"type":"text","value":"，所以这个环境变量的值就是在开发环境里定义的 nid_nest_api 的值，也就是 "},{"type":"element","tag":"a","props":{"href":"http://localhost/","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"http://localhost"}]},{"type":"text","value":":3000。"}]}],"toc":{"title":"","searchDepth":2,"depth":2,"links":[{"id":"nodejs","depth":2,"text":"Node.js","children":[{"id":"安装-nodejs","depth":3,"text":"安装 Node.js"},{"id":"命令行工具","depth":3,"text":"命令行工具"},{"id":"软件包的安装源","depth":3,"text":"软件包的安装源"},{"id":"多版本-nodejs可选","depth":3,"text":"多版本 Node.js（可选）"},{"id":"软件包编译环境","depth":3,"text":"软件包编译环境"}]},{"id":"mysql","depth":2,"text":"MySQL","children":[{"id":"macos安装-mysql","depth":3,"text":"macOS：安装 MySQL"},{"id":"macos管理-mysql-服务","depth":3,"text":"macOS：管理 MySQL 服务"},{"id":"windows安装-mysql","depth":3,"text":"Windows：安装 MySQL"},{"id":"windows管理-mysql-服务","depth":3,"text":"Windows：管理 MySQL 服务"},{"id":"root-用户","depth":3,"text":"root 用户"}]},{"id":"tableplus","depth":2,"text":"TablePlus","children":[{"id":"连接-mysql-服务","depth":3,"text":"连接 MySQL 服务"},{"id":"创建数据仓库","depth":3,"text":"创建数据仓库"},{"id":"打开数据仓库","depth":3,"text":"打开数据仓库"},{"id":"管理数据仓库","depth":3,"text":"管理数据仓库"},{"id":"执行-sql","depth":3,"text":"执行 SQL"}]},{"id":"insomnia","depth":2,"text":"Insomnia","children":[{"id":"管理项目","depth":3,"text":"管理项目"},{"id":"请求集合","depth":3,"text":"请求集合"},{"id":"管理环境","depth":3,"text":"管理环境"},{"id":"管理请求","depth":3,"text":"管理请求"}]}]}},"_type":"markdown","_id":"content:docs:2.env:1.backend.md","_source":"content","_file":"docs/2.env/1.backend.md","_extension":"md"}