I have some questions regarding various rc
files in a typical node application, like .npmrc
, .babelrc
etc.
.[module]rc
naming convention or is it just a recommended format?[module]rc
would make it automatically available to the module? If so where will it be available?package.json
to load config. Which is recommended, package.json
or an rc file?gulpfile.js
with module.exports
? (I meant in the sense of recommendations, of course I know the difference and advantages of the js and rc files)Every time I search in google, I end up here and here, which is a tool to read rc file but doesn't explain what are they or how are they constructed and/or connected to the module.
Any insight would be really useful. Thanks
What is an RC file? RC files mostly belong to Visual Studio by Microsoft. An RC file is a resource script used by compilers for applications written in various programming languages. A resource script (RC) file contains information such as source file references, version information, and identifiers for an application.
It definitely does not mean Release candidate. The rc, taking from a ST post, can stand for various things, but I will take that in this context, it stands for Runtime configuration.
The rc at the end of a file is related to the phrase "run commands"; its use derives from the /etc/rc. * files used to start most Unix systems. The rc suffix is commonly used for any file that contains startup information for a program. Common rc files include .
npmrc is the configuration file that npm allows to be used globally or user level or project level to optimize your npm environment.
So first off, nicely-asked.
rc
dotfiles are configuration files that can vary in their use, formatting, and overall meaning. You can create .[whatever name you like]rc
files to inform whatever package you happen to be creating (provided another package isn't looking for the same one). Usually, they're useful for some sort of tool that acts on your source code and needs some tuning specific to your project. My understanding is that there were similar files that played an important role in UNIX systems in years past and the idea has stuck.
In short:
.[program or binary name]rc
package.json
files can contain external metadata appropriate for config, it just depends on whether or not your project will expect a .rc
file or expect it in package.json
(or both, as in the case of babel)See also:
As an incredibly-simple example:
Say you wanted to read this .foorc
file that uses JSON encoding:
{ "cool": true }
You could do something like this:
'use strict'; const fs = require('fs'); fs.readFile('./.foorc', 'utf8', (err, data) => { if (err) throw new Error(err); console.log(JSON.parse(data)); })
There are far, far better ways to do this, but you could easily either write your own or find a package that would support YAML, ini, etc. parsing and provide some other nice bits of an API, too (for example, rc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With