What is @netlify/config?
@netlify/config is a package that helps you programmatically access and manipulate Netlify configuration settings. It allows you to read, validate, and modify the configuration settings for a Netlify site, making it easier to manage and automate deployment settings.
What are @netlify/config's main functionalities?
Load Netlify Configuration
This feature allows you to load the Netlify configuration for a site. The `loadConfig` function reads the configuration file and returns the configuration object, which you can then manipulate or inspect.
const { loadConfig } = require('@netlify/config');
(async () => {
const { config } = await loadConfig();
console.log(config);
})();
Validate Netlify Configuration
This feature allows you to validate the Netlify configuration. The `validateConfig` function checks the configuration object for any errors or inconsistencies, ensuring that the configuration is correct before deployment.
const { validateConfig } = require('@netlify/config');
(async () => {
const { config } = await loadConfig();
const validationResult = validateConfig(config);
console.log(validationResult);
})();
Modify Netlify Configuration
This feature allows you to modify the Netlify configuration. You can load the configuration, make changes to it, and then save the updated configuration back to the file.
const { loadConfig, saveConfig } = require('@netlify/config');
(async () => {
const { config } = await loadConfig();
config.build.command = 'npm run build';
await saveConfig(config);
console.log('Configuration updated');
})();
Other packages similar to @netlify/config
config
The 'config' package is a popular configuration management tool for Node.js applications. It allows you to define configuration settings for different environments and access them programmatically. Unlike @netlify/config, which is specific to Netlify, 'config' is a general-purpose tool that can be used in any Node.js application.
dotenv
The 'dotenv' package loads environment variables from a .env file into process.env. It is commonly used to manage configuration settings in Node.js applications. While 'dotenv' is more focused on environment variables, @netlify/config provides a more comprehensive solution for managing Netlify-specific configuration settings.
rc
The 'rc' package is a simple configuration loader for Node.js that supports configuration files, environment variables, and command-line arguments. It is more lightweight compared to @netlify/config and is suitable for applications that need a flexible and straightforward configuration management solution.
Netlify Config
Library for reading netlify configuration files.
About
@netlify/config
brings a wide variety of new functionality to Netlify's config ecosystem.
Including:
- Multiple config formats
environment
variable support- (Future)
secret
support
Environment Variable Support
To reference env
variables in your config file. Use the ${}
bracket notation.
${env:MY_VARIABLE_KEY_NAME}
Example
thing: ${env:MY_VAR}
Example with default value
thing: ${env:OTHER_VAR, 'my-default-value'}
Formats
Currently yml
, toml
, and json
are supported by @netlify/config
Format Examples
netlify.toml
!
[build]
publish = "dist"
command = "npm run build"
functions = "functions"
netlify.yml
!
build:
publish: dist
command: npm run build
functions: functions
netlify.json
!
{
"build": {
"publish": "dist",
"command": "npm run build",
"functions": "functions"
}
}