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

To install the Layer0 CLI run

npm i -g @layer0/cli

Or with yarn:

yarn global add @layer0/cli

Creates a build of your app optimized for production

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.

layer0 build

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

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.

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

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

layer0 completion

layer0 completion >> ~/.zshrc

layer0 completion >> ~/.bashrc

Builds and deploys your site on Layer0.

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.

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.

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

{
  "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 */
  }
}

layer0 deploy my-team --environment=production

Open the Layer0 documentation in your browser.

layer0 docs

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

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

layer0 dev

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

layer0 init

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

Logs into Layer0 via the developer console.

layer0 login

Logs out of Layer0

layer0 logout

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

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 layer0 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.

layer0 run --production

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

layer0 run /path/to/bundle.zip

Production mode is always used whe running downloaded bundles.

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

To install a particular version:

layer0 use 1.45.0

To install the latest stable:

layer0 use latest

To install the latest preview:

layer0 use next


An uncommon issue when running layer0 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 layer0 init on the project.