From 4fe866c67153d3950c1ab20deed9a4b0cd356e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=98=A5=E7=BF=94=EF=BC=88=E7=A9=B7=E5=91=90-?= =?UTF-8?q?=EF=BC=89?= <907079131@qq.com> Date: Thu, 29 Feb 2024 23:40:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=98=BF=E5=B7=B4=E9=98=BF=E5=B7=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20240229_\345\210\235\350\256\244node.md" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "\346\236\227\346\230\245\347\277\224/20240229_\345\210\235\350\256\244node.md" diff --git "a/\346\236\227\346\230\245\347\277\224/20240229_\345\210\235\350\256\244node.md" "b/\346\236\227\346\230\245\347\277\224/20240229_\345\210\235\350\256\244node.md" new file mode 100644 index 0000000..a764082 --- /dev/null +++ "b/\346\236\227\346\230\245\347\277\224/20240229_\345\210\235\350\256\244node.md" @@ -0,0 +1,24 @@ +## node.js和环境变量的关系 +在 Node.js中,环境变量是可以在操作系统中设置并在 Node.js 应用程序中访问的特殊变量。环境变量可以用来在不同的环境中配置应用程序的行为,例如数据库连接信息、API密钥等敏感信息。 + +你可以在启动 Node.js 应用程序时通过命令行获取环境变量,例如: +```js +console.log(process.env) +``` +```js +{ + PATH: '/usr/local/bin:/usr/bin', + JAVAHOME: '/usr/lib/Java', + ... +} +``` + +## node.js项目初始化 +1. 确保你已经安装了 Node.js。可以在终端中运行 `node -v` 命令来检查 Node.js 是否已安装和版本号。 +2. 创建一个新的项目文件夹,并进入该文件夹 +3. 初始化 Node.js 项目。在终端中运行以下命令: +```js +npm init -y +``` +完成后将会生成一个 `package.json` 文件,其中包含了你的项目的配置信息。 +4. 开发你的 Node.js 项目。在项目文件夹中创建你的 JavaScript 文件,并编写代码。 \ No newline at end of file -- Gitee From d4ad5d861394e910310040862b7f689be1d181ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=98=A5=E7=BF=94=EF=BC=88=E7=A9=B7=E5=91=90-?= =?UTF-8?q?=EF=BC=89?= <907079131@qq.com> Date: Sat, 2 Mar 2024 13:00:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=98=BF=E5=B7=B4=E9=98=BF=E5=B7=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20240301_node\346\250\241\345\235\227.md" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "\346\236\227\346\230\245\347\277\224/20240301_node\346\250\241\345\235\227.md" diff --git "a/\346\236\227\346\230\245\347\277\224/20240301_node\346\250\241\345\235\227.md" "b/\346\236\227\346\230\245\347\277\224/20240301_node\346\250\241\345\235\227.md" new file mode 100644 index 0000000..6ada5e9 --- /dev/null +++ "b/\346\236\227\346\230\245\347\277\224/20240301_node\346\250\241\345\235\227.md" @@ -0,0 +1,20 @@ +## 模块 +模块就是将文件里面定义好功能的函数和对象看成一个结合体,当用户调用模块就相当于拥有了这个模块里面的所有功能。 +### 模块化好处 +1. 方便维护,代码定位准确 +2. 内部的变量,相互不影响,方便单个模块功能调试、升级,方便模块间组合、分解 +3. 方便团队开发,多人协作互不干扰 +4. 模块可以复用 +## 暴露 +```js +'use strict';// 严格模式 + +var a = 'Hello'; + +function something(text) { + console.log(a + ', ' + text + '!'); +} + +module.exports = something;// 暴露语句 +``` +可以将函数greet作为模块的输出暴露出去,这样其他模块就可以使用greet函数了。 \ No newline at end of file -- Gitee