Note
Before you start, check out the Upsun demo app and the main Getting started guide. They provide all of the core concepts and common commands you need to know before using the materials below.1. Create an Express app
To create your Express app, follow these steps.-
Follow the Express installation guide.
To fast track the process, run the following commands:
Terminal
-
To initialize the local Git repository and commit local files, run the following commands:
Terminal
You can view your running app locally by installing dependencies (
npm install) and running npm run dev.
The local server is visible at localhost:3000.2. Create a new project
To create a project on Upsun, follow these steps.Remember
After creating your Upsun project, copy your new project ID for later use.- Using the CLI
- Using the Console
To create a new project with the Upsun CLI, use the following command and follow the prompts:
Terminal
When creating a new project using the Upsun CLI command
project:create,
you are asked if you want to set the local remote to your new project. Enter Yes (y).Your local source code is automatically linked to your newly created Upsun project
through the creation of a .upsun/local/project.yaml.
This file contains the corresponding <projectId> for the Upsun CLI to use,
and sets a Git remote to upsun.3. Choose your Git workflow
You can use Upsun projects as a classic Git repository, where you are able to push your source code in different ways, using either the Git CLI or the Upsun CLI. You can choose which way —or Git workflow— you want to use for your project from the following options:- Your project source code is hosted on an Upsun Git repository
- Your project source code is hosted on your own GitHub repository
- Upsun Git repository
- GitHub repository
For the rest of this guide, you will use the normal Git workflow (
git add . && git commit -m "message" && git push upsun) to commit your source code changes to Git history.
You will also use the Upsun CLI to deploy your Upsun environment with the latest code updates.4. Configure your project
To host your Express application on Upsun, you need to have a few YAML configuration files at the root of your project. These files manage your app’s behavior. They are located in a.upsun/ folder at the root of your source code
and structured in a similar way to this:
Terminal
5. Deploy
And just like that, it’s time to deploy! Depending on the Git workflow you chose at the beginning of this tutorial, there are two ways to deploy your source code changes.- Using Upsun Git repository
- Using a third-party Git repository
You can push your code using the normal Git workflow (
git add . && git commit -m "message" && git push). This pushes your source code changes to your upsun remote repository. Alternatively, you can use the following Upsun CLI command:Terminal
Tip
Each environment has its own domain name. To open the URL of your new environment, run the following command:Terminal
6. Make changes to your project
Now that your project is deployed, you can start making changes to it. For example, you might want to fix a bug or add a new feature. In your project, themain branch always represents the production environment.
Other branches are for developing new features, fixing bugs, or updating the infrastructure.
To make changes to your project, follow these steps:
-
Create a new environment (a Git branch) to make changes without impacting production:
This command creates a new localTerminal
feat-aGit branch based on the main Git branch, and activates a related environment on Upsun. The new environment inherits the data (service data and assets) of its parent environment (the production environment here). -
Make changes to your project.
For example, edit the
views/index.jadefile and make the following changes: -
Commit your changes:
Terminal
-
Deploy your changes to the
feat-aenvironment:Terminal -
Iterate by changing the code, committing, and deploying.
When satisfied with your changes, merge them to the main branch,
and remove the feature branch:
Note that deploying to production is fast because the image built for the
feat-aenvironment is reused. For a long running branch, to keep the code up-to-date with the main branch, usegit merge mainorgit rebase main. You can also keep the data in sync with the production environment by usingupsun env:sync.