Getting started with local development
The HubSpot CLI (Command Line Interface) connects your local workflow to HubSpot, allowing you to utilize version control, your favorite text editor and various web development technologies when developing on CMS Hub.
This guide is best for folks who are familiar already with the CMS but want to learn about working with the CLI. If you are completely new to HubSpot CMS Hub development, we encourage you to:
The HubSpot CLI is used to
watch files from the developer file system. Building with the CLI means you'll have local copies of your assets. Because you have the code locally you can use your preferred code editor, you can use build tools, you can commit your code to a git repository.
Additionally the CLI has helper functionality that can speed up your development. For example the
hs create command gives you ways to quickly create different types of assets locally, from modules to creating a theme from the boilerplate.
In this guide, we'll walk through installing the CLI, and the core features of the CLI fetching a project from your HubSpot account, and then uploading changes back to your Design Tools.
For more commands and local file formats, see the Local Development Tooling Reference.
To use the local tooling, you'll need to:
- To install the HubSpot tools globally, run npm install -g @hubspot/cli in your command line. To install the tools in your current directory, run npm install @hubspot/cli.
Create a folder for your local project. For example, run mkdir local-cms-dev in the command line, which will create a directory. Then, run cd local-cms-dev to navigate to that directory.
hs init to connect the tools to your HubSpot account. This command will walk you through the following steps:
- First you’ll be guided to create a personal CMS access key to enable authenticated access to your account via the local development tools. You’ll be prompted to press "Enter" when you’re ready to open the Personal CMS Access Key page in your default browser. This page will allow you to view or generate your personal access key, if necessary. (Note: You’ll need to select at least the "Design Manager" permission in order to complete this tutorial.) Copy your access key and paste it in the terminal.
- Next, you’ll enter a name for the account. This name is only seen and used by you, For example, you might use "sandbox" if you're using a developer sandbox or "company.com" if you’re using a full customer account. This name can't contain spaces. This name will be used when running commands.
Once you've completed this simple init flow, you'll see a success message confirming that a configuration file, hubspot.config.yml, has been created in your current directory.
Your hubspot.config.yml will look something like this:
When running commands, either name or portalId can be used in the --account= option (ex. --account=123 and --account=sandbox will both interact with account ID 123 based on the above example). If you set a top-level defaultPortal, you can exclude the --account= option from your commands, commands will reference that default portal.
Using the fetch command, run hs fetch --account=<name> <src> <dest> to get an entire projects folder tree and files from your HubSpot account into your local environment. The src is the project path in your HubSpot Design Tools, and the dest is the path to the local directory you would like the files to be placed, relative to your current working directory. To fetch the project to your current working directory, you can leave out the <dest> argument.
Here is an example of how you would fetch a project from your HubSpot account:
This is the Design Tools project we fetched to our local environment:
Using the upload command, run hs upload --account=<name> <src> <dest> to upload the project in your local environment to your HubSpot account. This will copy the contents of the <src> and upload them to your HubSpot account in the <dest>. If you're creating a new project in your Design Tools, the <dest> can be a net new folder in HubSpot.
Here is an example of how you would upload the example project into your HubSpot account:
Run hs watch --account=<name> <src> <dest> to watch your local directory and automatically upload changes to your HubSpot account on file saves.
Here is an example of how you would run that command with the watch command:
Thank you for your feedback, it means a lot to us.