Build & Start command

The build command and run command are essential for preparing and starting your application.

Overview

The build command and run command are essential for preparing and starting your application. These commands are executed inside the working directory and must be correctly defined to ensure the application runs smoothly.

  • The build command installs dependencies and compiles or prepares the application for execution.

  • The run command starts the application, making it available for requests.

Example usage

Node.js application

Repository structure

/my-repo
│── package.json
│── server.js
│── .gitignore  # Ensure node_modules/ is ignored

Build command

npm install

Run command

node server.js

Fastapi application

Repository structure

/my-repo
│── requirements.txt
│── main.py
│── app/

Build command

pip install -r requirements.txt

Run command

uvicorn main:app --host 0.0.0.0 --port 8000

Django application

Repository structure

/my-repo
│── requirements.txt
│── manage.py
│── myproject/

Build command

pip install -r requirements.txt

Run command

python manage.py runserver 0.0.0.0:8000

Go application

Repository structure

/my-repo
│── main.go
│── go.mod
│── go.sum

Build command

go build -o app .

Run command

./app

Advanced usage

Sometimes, additional commands need to be executed before starting the application. For example, running database migrations before launching the server. You can join multiple commands using &&, or simply place them on a new line, which automatically joins them with &&.

Running database migrations before starting the application

Django example

python manage.py migrate && python manage.py runserver 0.0.0.0:8000

Or written on multiple lines:

python manage.py migrate
python manage.py runserver 0.0.0.0:8000

Fastapi example (using alembic migrations)

alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8000

Or written on multiple lines:

alembic upgrade head
uvicorn main:app --host 0.0.0.0 --port 8000

Conclusion

Setting the correct build command and run command ensures your application installs dependencies and starts correctly. Always verify these commands based on your application’s framework and dependencies.

Last updated