@netlify/config
Netlify config module
Last updated a day ago by netlify-bot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @netlify/config 
SYNC missed versions from official npm registry.

Netlify Config

This library loads, validates, and normalizes the Netlify configuration.

Netlify can be configured:

Install

npm install @netlify/config

Usage (Node.js)

getNetlifyConfig(options?)

options: object?
Return value: Promise<object>

const getNetlifyConfig = require('@netlify/config')

const exampleFunction = async function () {
  const { config, configPath, buildDir, context, branch, token, siteInfo } = await getNetlifyConfig(options)
  // {
  // "siteInfo": {
  //   "id": "418b94bc-93cd-411a-937a-ae4c734f17c4",
  //   "name": "mick",
  //   "build_settings": {
  //     "cmd": "",
  //     "dir": "",
  //     "env": { ... },
  //     "functions_dir": "",
  //     "base": "",
  //   },
  //   ...
  // },
  // "accounts": [
  //   {
  //     "name": "my team",
  //     "slug": "me",
  //     ...
  //   },
  //   ...
  // ],
  // "addons": [],
  // "env": {
  //   "NODE_VERSION": { "sources": ["configFile"], "value": "16" },
  //   ...
  // },
  // "configPath": "/home/me/code/cv-website/netlify.toml",
  // "buildDir": "/home/me/code/cv-website",
  // "repositoryRoot": "/home/me/code/cv-website",
  // "config": {
  //   "functionsDirectory": "/home/me/code/cv-website/netlify/functions",
  //   "functionsDirectoryOrigin": "default",
  //   "functions": { "*": { "node_bundler": "esbuild" } },
  //   "plugins": [
  //     {
  //       "package": "@netlify/plugin-sitemap",
  //       "inputs": {},
  //       "origin": "config"
  //     }
  //   ],
  //   "build": {
  //     "publish": "/home/me/code/cv-website/build",
  //     "publishOrigin": "default",
  //     "command": "gulp build",
  //     "commandOrigin": "config",
  //     "functions": "/home/me/code/cv-website/netlify/functions"
  //   }
  // },
  // "context": "production",
  // "branch": "main",
  // "token": "564194bc-12cd-511a-037a-be4c734f17c4"
  // }
}

Options

The options are an optional object with the following properties.

Those options are automatically set when using @netlify/config in the Netlify production CI or with Netlify CLI.

debug

Type: boolean
Default value: false unless the NETLIFY_BUILD_DEBUG environment variable is set.

Prints debugging information showing the configuration being resolved.

offline

Type: boolean
Default value: false

Do not send requests to the Netlify API to retrieve site settings.

buffer

Type: boolean
Default value: false

When using debug, returns the logs instead of printing them on the console.

config

Type: string

Path to the netlify.toml. It is either an absolute path or a path relative to the cwd.

If not specified, it is searched in the following directories (by highest priority order):

  • base directory
  • repositoryRoot
  • current directory
  • any parent directory

Otherwise, no netlify.toml is used.

repositoryRoot

Type: string
Default value: see cwd

Repository root directory. This is used in the following cases:

  • Searching for the netlify.toml (see config)
  • When a base directory was specified, its path is relative to the repository root directory
  • The functions, edge_handlers and publish directories are relative to the repository root directory or (if specified) the base directory
  • Determining the build directory

If not specified, it is automatically guessed by looking for any .git directory from the cwd, and up. If none is found, the cwd is used instead.

cwd

Type: string
Default value: process.cwd()

Current directory. This is used in the following cases:

  • Searching for the netlify.toml (see config)
  • Searching for the repositoryRoot
  • In a monorepo, when stepping inside a specific package in the console, that package is automatically used as base directory

context

Type: string
Default value: environment variable CONTEXT, or "production"

Deploy context.

The netlify.toml can contain contexts.{CONTEXT} properties, which are like build properties but only applied when {CONTEXT} matches.

branch

Type: string
Default value: environment variable BRANCH, current git branch, "main" or "master".

Same as context but using a git branch name.

token

Type: string
Default value: environment variable NETLIFY_AUTH_TOKEN

Netlify API token.

This is used to retrieve siteInfo.

host

Type: string
Default value: api.netlify.com

Host of the Netlify API.

scheme

Type: string
Default value: https

Scheme/protocol of the Netlify API.

pathPrefix

Type: string
Default value: /api/v1

Base path prefix of the Netlify API.

siteId

Type: string
Default value: environment variable NETLIFY_SITE_ID

Netlify Site ID.

This is used to retrieve siteInfo, accounts and addons.

env

Type: object

Environment variable to use, in addition to the current process.env. This is used as the default values of other options.

mode

Type: string
Default value: "require"

What is calling @netlify/config. Can be:

  • "buildbot": Netlify production CI
  • "cli": Netlify CLI
  • "require": anything else

This is used for the following cases:

  • if mode is buildbot, siteInfo, accounts and addons are not retrieved because they are also passed using another internal option.

defaultConfig

Type: string

Configuration object used as default. This is an object serialized with JSON.

inlineConfig

Type: object

Configuration object overriding any properties. This is a JavaScript object.

configMutations

Type: array

Array of changes to apply to the configuration. Each change must be an object with three properties:

  • keys: array of keys targetting the property to change
  • value: new value of that property
  • event: build event when this change was applied, e.g. onPreBuild

Return value

The return value is a Promise resolving to an object with the following properties.

config

Type: object

Resolved configuration object.

configPath

Type: string?

Absolute path to the netlify.toml, if this file exists.

headersPath

Type: string

Absolute path to the _headers, even if this file does not exist.

redirectsPath

Type: string

Absolute path to the _redirects, even if this file does not exist.

buildDir

Type: string

Absolute path to the build directory.

The build directory is the current directory in which most build operations, including the build command, execute. It is usually either the repositoryRoot or (if specified) the base directory.

repositoryRoot

Type: string

The computed value of repositoryRoot.

context

Type: string

Resolved context. See the context option.

branch

Type: string

Resolved git branch. See the branch option.

siteInfo

Type: object

Netlify Site information retrieved using the getSite Netlify API endpoint. This is used to retrieve Build settings set in the Netlify App: plugins, Build command, Publish directory, Functions directory, Base directory, Environment variables.

This might be empty depending on the options passed.

accounts

Type: object[]

Netlify accounts retrieved using the listAccountsForUser Netlify API endpoint. This is used to retrieve account-level environment variables.

This might be empty depending on the options passed.

addons

Type: object[]

Netlify addons retrieved using the listServiceInstancesForSite Netlify API endpoint. This is used to retrieve addon-specific environment variables.

This might be empty depending on the options passed.

token

Type: string

Netlify API token. This takes into account the token option but also some Netlify-specific environment variables.

api

Type: NetlifyClient?

Netlify JavaScript client instance used to retrieve siteInfo, accounts and addons.

logs

Type: object?

When the buffer option is used, this contains two arrays stdout and stderr with the logs.

env

Type: object?

Site's environment variables. Each environment variable value is an object with the following properties:

  • value string
  • sources string[] among:
    • general: general environment variables set for all sites
    • account: environment variables set in the Netlify UI for a specific account
    • addons: addon-specific environment variables
    • ui: environment variables set in the Netlify UI for a specific site
    • configFile: environment variables set in netlify.toml

Usage (CLI)

$ netlify-config

Like getNetlifyConfig(), but in the CLI. The return value is printed on stdout.

The CLI flags use the same options.

Current Tags

  • 2.4.4-0                                ...           beta (9 months ago)
  • 2.1.5-3                                ...           debug (a year ago)
  • 15.7.2                                ...           latest (a day ago)

305 Versions

  • 15.7.2                                ...           a day ago
  • 15.7.1                                ...           2 days ago
  • 15.7.0                                ...           4 days ago
  • 15.6.7                                ...           5 days ago
  • 15.6.6                                ...           8 days ago
  • 15.6.5                                ...           9 days ago
  • 15.6.4                                ...           12 days ago
  • 15.6.3                                ...           25 days ago
  • 15.6.2                                ...           a month ago
  • 15.6.1                                ...           a month ago
  • 15.6.0                                ...           a month ago
  • 15.5.2                                ...           a month ago
  • 15.5.1                                ...           2 months ago
  • 15.5.0                                ...           2 months ago
  • 15.4.1                                ...           2 months ago
  • 15.4.0                                ...           2 months ago
  • 15.3.8                                ...           2 months ago
  • 15.3.7                                ...           2 months ago
  • 15.3.6                                ...           2 months ago
  • 15.3.5                                ...           2 months ago
  • 15.3.4                                ...           2 months ago
  • 15.3.3                                ...           2 months ago
  • 15.3.2                                ...           2 months ago
  • 15.3.1                                ...           2 months ago
  • 15.3.0                                ...           2 months ago
  • 15.2.0                                ...           2 months ago
  • 15.1.9                                ...           2 months ago
  • 15.1.8                                ...           2 months ago
  • 15.1.7                                ...           2 months ago
  • 15.1.6                                ...           2 months ago
  • 15.1.5                                ...           2 months ago
  • 15.1.4                                ...           2 months ago
  • 15.1.3                                ...           2 months ago
  • 15.1.2                                ...           2 months ago
  • 15.1.1                                ...           2 months ago
  • 15.1.0                                ...           2 months ago
  • 15.0.5                                ...           2 months ago
  • 15.0.4                                ...           2 months ago
  • 15.0.3                                ...           2 months ago
  • 15.0.2                                ...           2 months ago
  • 15.0.1                                ...           2 months ago
  • 15.0.0                                ...           2 months ago
  • 14.4.3                                ...           2 months ago
  • 14.4.2                                ...           2 months ago
  • 14.4.1                                ...           2 months ago
  • 14.4.0                                ...           2 months ago
  • 14.3.0                                ...           2 months ago
  • 14.2.0                                ...           2 months ago
  • 14.1.1                                ...           2 months ago
  • 14.1.0                                ...           3 months ago
  • 14.0.0                                ...           3 months ago
  • 13.0.0                                ...           3 months ago
  • 12.6.0                                ...           3 months ago
  • 12.5.0                                ...           3 months ago
  • 12.4.0                                ...           3 months ago
  • 12.3.0                                ...           3 months ago
  • 12.2.1                                ...           3 months ago
  • 12.2.0                                ...           3 months ago
  • 12.1.1                                ...           3 months ago
  • 12.1.0                                ...           3 months ago
  • 12.0.1                                ...           3 months ago
  • 12.0.0                                ...           3 months ago
  • 11.0.0                                ...           3 months ago
  • 10.3.0                                ...           3 months ago
  • 10.2.0                                ...           3 months ago
  • 10.1.0                                ...           3 months ago
  • 10.0.0                                ...           3 months ago
  • 9.8.0                                ...           3 months ago
  • 9.7.0                                ...           3 months ago
  • 9.6.0                                ...           3 months ago
  • 9.5.0                                ...           4 months ago
  • 9.4.0                                ...           4 months ago
  • 9.3.0                                ...           4 months ago
  • 9.2.0                                ...           4 months ago
  • 9.1.0                                ...           4 months ago
  • 9.0.0                                ...           4 months ago
  • 8.0.1                                ...           4 months ago
  • 8.0.0                                ...           4 months ago
  • 7.7.1                                ...           4 months ago
  • 7.7.0                                ...           4 months ago
  • 7.6.0                                ...           4 months ago
  • 7.5.0                                ...           4 months ago
  • 7.4.1                                ...           4 months ago
  • 7.4.0                                ...           4 months ago
  • 7.3.0                                ...           4 months ago
  • 7.2.4                                ...           4 months ago
  • 7.2.3                                ...           4 months ago
  • 7.2.2                                ...           4 months ago
  • 7.2.1                                ...           4 months ago
  • 7.2.0                                ...           4 months ago
  • 7.1.2                                ...           4 months ago
  • 7.1.1                                ...           4 months ago
  • 7.1.0                                ...           4 months ago
  • 7.0.3                                ...           4 months ago
  • 7.0.2                                ...           4 months ago
  • 7.0.1                                ...           4 months ago
  • 6.10.1                                ...           4 months ago
  • 7.0.0                                ...           4 months ago
  • 6.10.0                                ...           4 months ago
  • 6.9.2                                ...           4 months ago
  • 6.9.1                                ...           4 months ago
  • 6.9.0                                ...           4 months ago
  • 6.8.0                                ...           4 months ago
  • 6.7.3                                ...           4 months ago
  • 6.7.2                                ...           4 months ago
  • 6.7.1                                ...           5 months ago
  • 6.7.0                                ...           5 months ago
  • 6.6.0                                ...           5 months ago
  • 6.5.0                                ...           5 months ago
  • 6.4.4                                ...           5 months ago
  • 6.4.3                                ...           5 months ago
  • 6.4.2                                ...           5 months ago
  • 6.4.1                                ...           5 months ago
  • 6.4.0                                ...           5 months ago
  • 6.3.2                                ...           6 months ago
  • 6.3.1                                ...           6 months ago
  • 6.3.0                                ...           6 months ago
  • 6.2.1                                ...           6 months ago
  • 6.2.0                                ...           6 months ago
  • 6.1.0                                ...           6 months ago
  • 6.0.3                                ...           6 months ago
  • 6.0.2                                ...           6 months ago
  • 6.0.1                                ...           6 months ago
  • 6.0.0                                ...           6 months ago
  • 5.12.0                                ...           6 months ago
  • 5.11.1                                ...           6 months ago
  • 5.11.0                                ...           6 months ago
  • 5.10.0                                ...           6 months ago
  • 5.9.0                                ...           6 months ago
  • 5.8.0                                ...           6 months ago
  • 5.7.0                                ...           6 months ago
  • 5.6.0                                ...           6 months ago
  • 5.5.1                                ...           6 months ago
  • 5.5.0                                ...           6 months ago
  • 5.4.0                                ...           6 months ago
  • 5.3.1                                ...           6 months ago
  • 5.3.0                                ...           6 months ago
  • 5.2.0                                ...           6 months ago
  • 5.1.1                                ...           6 months ago
  • 5.1.0                                ...           7 months ago
  • 5.0.1                                ...           7 months ago
  • 5.0.0                                ...           7 months ago
  • 4.3.0                                ...           7 months ago
  • 4.2.0                                ...           7 months ago
  • 4.1.3                                ...           7 months ago
  • 4.1.2                                ...           7 months ago
  • 4.1.1                                ...           7 months ago
  • 4.1.0                                ...           7 months ago
  • 4.0.4                                ...           7 months ago
  • 4.0.2                                ...           8 months ago
  • 4.0.1                                ...           8 months ago
  • 4.0.0                                ...           8 months ago
  • 3.1.2                                ...           8 months ago
  • 3.1.1                                ...           9 months ago
  • 3.1.0                                ...           9 months ago
  • 3.0.5                                ...           9 months ago
  • 3.0.4                                ...           9 months ago
  • 3.0.3                                ...           9 months ago
  • 3.0.2                                ...           9 months ago
  • 3.0.1                                ...           9 months ago
  • 3.0.0                                ...           9 months ago
  • 2.4.4-0                                ...           9 months ago
  • 2.4.3                                ...           9 months ago
  • 2.4.2                                ...           10 months ago
  • 2.4.1                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.6                                ...           a year ago
  • 2.3.5                                ...           a year ago
  • 2.3.4                                ...           a year ago
  • 2.3.3                                ...           a year ago
  • 2.3.2                                ...           a year ago
  • 2.3.1                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.5                                ...           a year ago
  • 2.1.5-3                                ...           a year ago
  • 2.1.5-2                                ...           a year ago
  • 2.1.5-1                                ...           a year ago
  • 2.1.5-0                                ...           a year ago
  • 2.1.4                                ...           a year ago
  • 2.1.3                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.10                                ...           a year ago
  • 2.0.9                                ...           a year ago
  • 2.0.8                                ...           a year ago
  • 2.0.7                                ...           a year ago
  • 2.0.6                                ...           a year ago
  • 2.0.5                                ...           a year ago
  • 2.0.4                                ...           a year ago
  • 2.0.3                                ...           a year ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.2.6-1                                ...           a year ago
  • 1.2.6-0                                ...           a year ago
  • 1.2.5                                ...           a year ago
  • 1.2.4                                ...           a year ago
  • 1.2.3                                ...           a year ago
  • 1.2.2                                ...           a year ago
  • 1.2.2-0                                ...           a year ago
  • 1.2.1                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.3-2                                ...           a year ago
  • 1.1.3-1                                ...           a year ago
  • 1.1.3-0                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.10                                ...           a year ago
  • 1.0.9                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4-0                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.12.0                                ...           a year ago
  • 0.11.11                                ...           a year ago
  • 0.11.10                                ...           a year ago
  • 0.11.9                                ...           a year ago
  • 0.11.8                                ...           a year ago
  • 0.11.7                                ...           a year ago
  • 0.11.6                                ...           a year ago
  • 0.11.5                                ...           a year ago
  • 0.11.4                                ...           a year ago
  • 0.11.3                                ...           a year ago
  • 0.11.3-0                                ...           a year ago
  • 0.11.2                                ...           a year ago
  • 0.11.1                                ...           a year ago
  • 0.9.0-debug.1                                ...           a year ago
  • 0.9.0-debug.0                                ...           a year ago
  • 0.11.0                                ...           a year ago
  • 0.10.4                                ...           a year ago
  • 0.10.3                                ...           a year ago
  • 0.10.2                                ...           a year ago
  • 0.10.1                                ...           2 years ago
  • 0.10.0                                ...           2 years ago
  • 0.9.2                                ...           2 years ago
  • 0.9.1                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.2                                ...           2 years ago
  • 0.5.1                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.12-rc.1                                ...           2 years ago
  • 0.4.12-beta.5                                ...           2 years ago
  • 0.4.12-beta.4                                ...           2 years ago
  • 0.4.12-beta.3                                ...           2 years ago
  • 0.4.12-beta.2                                ...           2 years ago
  • 0.4.12-beta.1                                ...           2 years ago
  • 0.4.12                                ...           2 years ago
  • 0.4.11                                ...           2 years ago
  • 0.4.10                                ...           2 years ago
  • 0.4.9                                ...           2 years ago
  • 0.4.8                                ...           2 years ago
  • 0.4.7                                ...           2 years ago
  • 0.4.6                                ...           2 years ago
  • 0.4.5                                ...           2 years ago
  • 0.4.4                                ...           2 years ago
  • 0.4.3                                ...           2 years ago
  • 0.4.2                                ...           2 years ago
  • 0.4.1                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.23                                ...           2 years ago
  • 0.1.22                                ...           2 years ago
  • 0.1.21                                ...           2 years ago
  • 0.1.20                                ...           2 years ago
  • 0.1.19                                ...           2 years ago
  • 0.1.18                                ...           2 years ago
  • 0.1.17                                ...           2 years ago
  • 0.1.16                                ...           2 years ago
  • 0.1.15                                ...           2 years ago
  • 0.1.14                                ...           2 years ago
  • 0.1.13                                ...           2 years ago
  • 0.1.12                                ...           2 years ago
  • 0.1.11                                ...           2 years ago
  • 0.1.10                                ...           2 years ago
  • 0.1.9                                ...           2 years ago
  • 0.1.8                                ...           2 years ago
  • 0.1.7                                ...           2 years ago
  • 0.1.6                                ...           2 years ago
  • 0.1.5                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Downloads
Today 0
This Week 1,017
This Month 1,147
Last Day 7
Last Week 123
Last Month 465
Dependencies (26)
Dev Dependencies (6)

Copyright 2014 - 2021 © npmmirror.com |