Skip to main content

Multiple Environments

Here's a guide on how to use Nhost with multiple environments and how to set up a workflow around them.

For this example, we'll set up one production environment and one staging environment.

Git

Create a new Git repo and use the CLI and the nhost init command to initialize a new project.

Also, create a new branch called staging.

You should now have a Git repo with a main branch and a staging branch.

Nhost Cloud

To have two environments, we need to create two projects on Nhost Cloud.

Both projects must be connected to the same Git repo, but using different deployment branches.

Set your production project to use the main branch as the Deployment Branch and your staging project to use the staging branch as the Deployment Branch. This way, the production project will only deploy new changes to the main branch and the staging project will only deploy new changes to the staging branch.

drawing

Development

Local

Now, use the CLI to do local development. And use a specific feature branch while doing development.

Staging

Once you're ready to test your changes to staging, create a pull request from your feature branch to the staging branch. Then, merge the pull request to staging.

This will automatically trigger a new deployment to the staging project on the Nhost platform.

Production

Once you've tested your changes in the staging environment, you can create a new pull request from the staging branch to the main branch. Then, merge the pull request to main.

This will automatically trigger a new deployment to the production project on the Nhost platform.

Summary

Now you have two environments, one for staging and one for production. You can use this workflow to do local development, and test your changes in a staging environment before deploying them to production.