什么是 nodejs 中的 `rc` 文件?
What are `rc` files in nodejs?
我对典型节点应用程序中的各种 rc
文件有一些疑问,例如 .npmrc
、.babelrc
等
- 什么是 rc 文件,我知道它是模块的运行时配置,但还有其他吗?
- rc 文件是否必须遵循
.[module]rc
命名约定,还是只是推荐的格式?
- 支持哪些格式? yaml 和 json 两种格式我都见过,它取决于模块使用的 reader 吗?
- 如何从模块的角度访问rc文件?将其命名为
[module]rc
是否会使其自动供模块使用?如果有,在哪里可以买到?
- 或者模块是否应该像使用该模块的应用程序中的任何其他文件一样访问该文件,并期望它采用可理解的格式? (这就是我现在正在做的,格式是json)
- 我也看到有人要求
package.json
加载配置。 package.json
还是 rc 文件推荐哪个?
- 此外,它与 javascript 文件如
gulpfile.js
和 module.exports
有何不同? (我说的是推荐意义上的,当然我知道js和rc文件的区别和优势)
每次我在 google 中搜索时,我都会得到 here and here,这是一个读取 rc 文件的工具,但没有解释它们是什么或它们是如何构造的 and/or 连接到模块。
任何见解都会非常有用。谢谢
不特定于Node或Babel,但*rc
文件一般是Unix系统中的配置文件
Configuration files also do more than just modify settings, they often
(in the form of an "rc file") run a set of commands upon startup (for
example, the "rc file" for a shell might instruct the shell to change
directories, run certain programs, delete or create files — many
things which do not involve modifying variables in the shell itself
and so were not in the shell's dotfiles).
This convention is borrowed from "runcom files" on the CTSS operating system.
This functionality
can and has been extended for programs written in interpreted
languages such that the configuration file is actually another program
rewriting or extending or customizing the original program; Emacs is
the most prominent such example.
The "rc" naming convention of "rc files" was inspired by the "runcom" facility mentioned above and does
not stand for "resource configuration", "runtime configuration", or
"remote control" as is often wrongly guessed.
"rc" files are traditionally files which end in the "(.)rc" suffix and
which contain data and information that is used as configuration
information for the associated program. Typically the name of that
program is the first part of the rc file's name, with the "(.)rc"
suffix being used to indicate the file's purpose, e.g. ".xinitrc",
".vimrc", ".bashrc", "xsane.rc".
Unix: from runcom files on the CTSS system 1962-63, via the startup script /etc/rc
Script file containing startup instructions for an
application program (or an entire operating system), usually a text
file containing commands of the sort that might have been invoked
manually once the system was running but are to be executed
automatically each time the system starts up. See also dot file.
换句话说,"rc" 只是从六十年代开始就存在的东西,并且从那时起就经常用于各种程序的配置文件,包括 Node、Babel 和许多其他的。
"rc"文件没有什么特别之处,它们几乎可以包含任何类型的数据,没有规范或其他限制。
首先,问得好。
rc
点文件是配置文件,其用途、格式和总体含义可能有所不同。您可以创建 .[whatever name you like]rc
文件来通知您正在创建的任何包(前提是另一个包不是在寻找相同的包)。通常,它们对于某些作用于 您的源代码的工具很有用,并且需要针对您的项目进行一些特定的调整。我的理解是,在过去的几年里,有类似的文件在 UNIX 系统中发挥了重要作用,并且这个想法一直存在。
简而言之:
- 它们不是特定于节点的。
- 它们只是另一个文件
- 就格式而言,它们几乎可以是任何格式——这仅取决于您将使用什么来解析和读取它们。 YAML、JSON 和 ini 可能是最常见的(至少我见过)。
- 在大多数情况下,他们似乎遵循惯例
.[program or binary name]rc
package.json
文件可以包含适用于配置的外部元数据,这仅取决于您的项目是否需要 .rc
文件或 package.json
文件(或两者,就像 babel)
另请参阅:
- What does "rc" mean in dot files
- http://www.faqs.org/docs/artu/ch10s03.html#ftn.id2941902
- https://en.wikipedia.org/wiki/Configuration_file
作为一个非常简单的例子:
假设您想阅读这个使用 JSON 编码的 .foorc
文件:
{
"cool": true
}
你可以这样做:
'use strict';
const fs = require('fs');
fs.readFile('./.foorc', 'utf8', (err, data) => {
if (err) throw new Error(err);
console.log(JSON.parse(data));
})
有很多更好的方法可以做到这一点,但您可以轻松地编写自己的方法或找到一个支持 YAML、ini 等解析的包,并提供 API,也是(例如,rc)
RC指的是
- 运行 命令
- run-time配置
https://en.wikipedia.org/wiki/Run_commands
“rc”后缀可以追溯到 Unix 的祖父母 CTSS。
它有一个名为 "runcom" 的 command-script 功能。早期的
Unixes 使用“rc”作为操作系统的名称
引导脚本,作为对 CTSS 运行com.
的致敬
我对典型节点应用程序中的各种 rc
文件有一些疑问,例如 .npmrc
、.babelrc
等
- 什么是 rc 文件,我知道它是模块的运行时配置,但还有其他吗?
- rc 文件是否必须遵循
.[module]rc
命名约定,还是只是推荐的格式? - 支持哪些格式? yaml 和 json 两种格式我都见过,它取决于模块使用的 reader 吗?
- 如何从模块的角度访问rc文件?将其命名为
[module]rc
是否会使其自动供模块使用?如果有,在哪里可以买到? - 或者模块是否应该像使用该模块的应用程序中的任何其他文件一样访问该文件,并期望它采用可理解的格式? (这就是我现在正在做的,格式是json)
- 我也看到有人要求
package.json
加载配置。package.json
还是 rc 文件推荐哪个? - 此外,它与 javascript 文件如
gulpfile.js
和module.exports
有何不同? (我说的是推荐意义上的,当然我知道js和rc文件的区别和优势)
每次我在 google 中搜索时,我都会得到 here and here,这是一个读取 rc 文件的工具,但没有解释它们是什么或它们是如何构造的 and/or 连接到模块。
任何见解都会非常有用。谢谢
不特定于Node或Babel,但*rc
文件一般是Unix系统中的配置文件
Configuration files also do more than just modify settings, they often (in the form of an "rc file") run a set of commands upon startup (for example, the "rc file" for a shell might instruct the shell to change directories, run certain programs, delete or create files — many things which do not involve modifying variables in the shell itself and so were not in the shell's dotfiles). This convention is borrowed from "runcom files" on the CTSS operating system.
This functionality can and has been extended for programs written in interpreted languages such that the configuration file is actually another program rewriting or extending or customizing the original program; Emacs is the most prominent such example.
The "rc" naming convention of "rc files" was inspired by the "runcom" facility mentioned above and does not stand for "resource configuration", "runtime configuration", or "remote control" as is often wrongly guessed.
"rc" files are traditionally files which end in the "(.)rc" suffix and which contain data and information that is used as configuration information for the associated program. Typically the name of that program is the first part of the rc file's name, with the "(.)rc" suffix being used to indicate the file's purpose, e.g. ".xinitrc", ".vimrc", ".bashrc", "xsane.rc".
Unix: from runcom files on the CTSS system 1962-63, via the startup script /etc/rc
Script file containing startup instructions for an application program (or an entire operating system), usually a text file containing commands of the sort that might have been invoked manually once the system was running but are to be executed automatically each time the system starts up. See also dot file.
换句话说,"rc" 只是从六十年代开始就存在的东西,并且从那时起就经常用于各种程序的配置文件,包括 Node、Babel 和许多其他的。
"rc"文件没有什么特别之处,它们几乎可以包含任何类型的数据,没有规范或其他限制。
首先,问得好。
rc
点文件是配置文件,其用途、格式和总体含义可能有所不同。您可以创建 .[whatever name you like]rc
文件来通知您正在创建的任何包(前提是另一个包不是在寻找相同的包)。通常,它们对于某些作用于 您的源代码的工具很有用,并且需要针对您的项目进行一些特定的调整。我的理解是,在过去的几年里,有类似的文件在 UNIX 系统中发挥了重要作用,并且这个想法一直存在。
简而言之:
- 它们不是特定于节点的。
- 它们只是另一个文件
- 就格式而言,它们几乎可以是任何格式——这仅取决于您将使用什么来解析和读取它们。 YAML、JSON 和 ini 可能是最常见的(至少我见过)。
- 在大多数情况下,他们似乎遵循惯例
.[program or binary name]rc
package.json
文件可以包含适用于配置的外部元数据,这仅取决于您的项目是否需要.rc
文件或package.json
文件(或两者,就像 babel)
另请参阅:
- What does "rc" mean in dot files
- http://www.faqs.org/docs/artu/ch10s03.html#ftn.id2941902
- https://en.wikipedia.org/wiki/Configuration_file
作为一个非常简单的例子:
假设您想阅读这个使用 JSON 编码的 .foorc
文件:
{
"cool": true
}
你可以这样做:
'use strict';
const fs = require('fs');
fs.readFile('./.foorc', 'utf8', (err, data) => {
if (err) throw new Error(err);
console.log(JSON.parse(data));
})
有很多更好的方法可以做到这一点,但您可以轻松地编写自己的方法或找到一个支持 YAML、ini 等解析的包,并提供 API,也是(例如,rc)
RC指的是
- 运行 命令
- run-time配置
https://en.wikipedia.org/wiki/Run_commands
“rc”后缀可以追溯到 Unix 的祖父母 CTSS。 它有一个名为 "runcom" 的 command-script 功能。早期的 Unixes 使用“rc”作为操作系统的名称 引导脚本,作为对 CTSS 运行com.
的致敬