CLI

This guide shows you everything you can do with the Layer0 command line interface.

Installation

To install, or upgrade to the latest, Layer0 CLI run

Terminal
npm i -g @layer0/cli@latest

Or with yarn

Terminal
yarn global add @layer0/cli@latest

Upgrade Project to Latest Version

If you already have a project running on Layer0 and you want to update packages to the most recent release of @layer0, simply run:

Terminal
0 use latest

Before deploying your site, verify that all functionality, including request/response data, is as expected.

Commands

build

Creates a build of your app optimized for production.

Options

NameDescription
--skip-frameworkAlias: “-s”. Skips the framework (Next.js, Vue, Angular, etc..) build and simply rebundles your router
--disable-permanent-assetsSet this to true to suppress errors like “Immutable file (…) content was changed” during deployment.
--include-sourcesIncludes all non-gitignored source files in the bundle uploaded to Layer0. This can be helpful when debugging, especially when working with Layer0 support. You can limit the files that are uploaded using the sources config in layer0.config.js.

Example

Terminal
0 build

cache-clear

Clears the cache. If neither --path nor --surrogate-key is specified, the entire cache for the specified environment will be cleared.

Options

NameDescription
--team(Required) The team name
--site(Required) The site name
--environment(Required) The environment name
--pathA path to clear. Use ”*” as a wildcard
--surrogate-keyClears all responses assigned to the specified surrogate key

Example

Terminal
0 cache-clear --team=my-team --site=my-site --environment=production --path=/p/*

completion

Creates a script that provides autocompletion for Layer0 CLI commands that can be installed in your shell.

Example

Terminal
0 completion

Using ZSH

Terminal
0 completion >> ~/.zshrc

Using BASH

Terminal
0 completion >> ~/.bashrc

deploy

Builds and deploys your site on Layer0.

Parameters

NameDescription
teamThe name of the team under which the site will be deployed. The site will be deployed to your private space will be used if omitted.

Options

NameDescription
--siteThe name of the site to deploy. By default the name field in package.json is used.
--environmentThe environment to deploy to. By default the default environment is used.
--branchThe name of the source control branch. This is automatically set when using Git.
--skip-buildSkips the build step
--tokenAuthenticates using a deploy token rather than your user credentials. Use this option when deploying from CI. Alternatively, you can also specify the deploy token by setting the LAYER0_DEPLOY_TOKEN environment variable.
--commit-urlThe URL at which the commit can be viewed in your source control provided. If your package.json provides the repository attribute the commit URL will be derived automatically if you use GitHub, GitLab, or BitBucket.
--include-sourcesIncludes all non-gitignored source files in the bundle uploaded to Layer0. This can be helpful when debugging, especially when working with Layer0 support. You can limit the files that are uploaded using the sources config in layer0.config.js.
--disable-permanent-assetsSet this to true to suppress errors like “Immutable file (…) content was changed” during deployment.

Getting Information about the Deployment

The layer0 deploy command writes a file called .layer0/deployment-manifest.json, which contains the following information:

JavaScript
{
  "number": /* the deployment number */,
  "url": /* the permalink URL for the deployment */,
  "environment": {
    "url": /* The edge URL for the deployment */,
    "name": /* The name of the environment that was deployed to */
  }
}

Example

Terminal
0 deploy my-team --environment=production

docs

Open the Layer0 documentation in your browser.

Example

Terminal
0 docs

dev

Runs your project in development mode, simulating the Layer0 cloud environment. This command is a simplified version of 0 run, with only the —cache option being supported.

Options

NameDescription
--cacheEnables caching during local development so that you can test the caching logic in your router.

Example

Terminal
0 dev

init

Run in an existing app to add all required packages and files need to publish your app on Layer0

Example

Terminal
0 init

Options

NameDescription
--connectorThe name of a specific connector package to install, or a path to a directory that implements the connector interface.

login

Logs into Layer0 via the developer console.

Example

Terminal
0 login

logout

Logs out of Layer0

Example

Terminal
0 logout

run

Runs your app locally. Uses port 3000 by default. You can change this by setting the PORT environment variable. For example: PORT=5000 0 run.

Options

NameDescription
--productionRuns a production build of your app, simulating the cloud environment. This can also be achieved by setting the NODE_ENV environment variable to true. You need to run 0 build first.
--cacheEnables caching during local development so that you can test the caching logic in your router. By default caching is turned off in local development to ensure you don’t see stale responses as you make changes to your code.

Example

Terminal
0 run --production

Or to run a deployment bundle downloaded from Layer0 Developer Console, use:

Terminal
0 run /path/to/bundle.zip

Production mode is always used when running downloaded bundles.

use

Switches the version of all @layer0/* packages in your project.

Example

To install a particular version:

Terminal
0 use 4.10.1

To install the latest stable:

Terminal
0 use latest

To install the latest preview:

Terminal
0 use next

Troubleshooting


Error: Cannot find module … on 0 init

An uncommon issue when running 0 init can present a similar error:

installing @layer0/core, @layer0/cli, @layer0/prefetch, @layer0/devtools, @layer0/angular… done. Error: Cannot find module ‘/Users/myUser/Projects/my-@layer0-poc/node_modules/@layer0/angular/bin/init’

This may be related to an outdated global version of Layer0 CLI. The telltale sign is reference to /bin/ in the module path. This is an old convention. Recommended approach would be to npm i -g @layer0/cli@latest and then run 0 init on the project.