Local development
Back to home
On this page
Once Your Express application has been deployed on Upsun, you might want to start develop your application locally.
If you’re new to Upsun, you might want to check out the philosophy of Upsun to get started on the best possible footing.
Before you begin
You need:
- Git. Git is the primary tool to manage everything your app needs to run. Push commits to deploy changes and control configuration through YAML files. These files describe your infrastructure, making it transparent and version-controlled.
- A Upsun account. If you don’t already have one, register for a trial account. You can sign up with an email address or an existing GitHub, Bitbucket, or Google account. If you choose one of these accounts, you can set a password for your Upsun account later.
- Required: the Upsun CLI. This lets you interact with your project from the command line. You can also do most things through the Web Console, but this guide focuses on using the CLI.
- Install node CLI (version >= 18.x)
- Install Docker Composer locally
Create a MariaDb Docker container
At the root of your project, create a docker-composer.yaml file with the following:
version: '3'
volumes:
data:
services:
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: express
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- data:/var/lib/mysql
ports:
- "3306:3306"And launch corresponding Docker container:
docker-compose up -d Adapt your Express application to use local Docker container
For your Express application to use the local Docker container, adapt your index.js file, function openConnection() with the following :
...
function openConnection() {
return mysql.createConnection({
host: (process.env.DB_HOST || '127.0.0.1'),
port: (process.env.DB_PORT || '3306'),
user: (process.env.DB_USERNAME || 'user'),
password: (process.env.DB_PASSWORD || 'password'),
database: (process.env.DB_DATABASE || 'express')
});
}
... Launch local Express application
To run your Express application locally, use the following:
node index.jsAnd then open your favorite browser with http://localhost:3000.
Note
You might want your colleague to be able to do the same, so feel free to commit your changes on your favorite Git repository to share them with your team.