Deploying a Deno Express application to Fly
In this tutorial you will learn how to deploy a containerized Deno Express application to Fly.
The final code of this article can be found here.
- A Fly account
- A computer with Deno, Docker, and Flyctl (the Fly CLI)
Nội Dung Chính
#
Creating the application
deps.ts
export
{
default
as
express }
from
"npm:[email protected]"
;
main.ts
import
{
express }
from
"./deps.ts"
;
const
application =
express
(
)
;
const
port =
8080
;
application
.
get
(
"/"
,
(
req,
res)
=>
{
res.
send
(
{
message:
"Hello, World!"
,
}
)
;
}
)
.
get
(
"/random"
,
(
req,
res)
=>
{
res.
send
(
{
number
:
Math
.
floor
(
Math
.
random
(
)
*
100
)
,
}
)
;
}
)
;
application.
listen
(
port,
(
)
=>
{
console
.
log
(
`
Application listening on port
${
port}
`
)
;
}
)
;
To run the application locally:
deno run -A main.ts
#
Containerizing the application
Dockerfile
FROM
denoland/deno:alpine-1.30.0
WORKDIR
/usr/src/app
COPY
deps.ts .
RUN
deno cache deps.ts
ADD
. .
RUN
deno cache main.ts
EXPOSE
8080
CMD
["run"
, "-A"
, "main.ts"
]
To build and run the container locally:
docker
build .
-t hello-world
docker
run -dp 8080
:8080 hello-world
#
Deploying the application
fly launch
to prepare yourfly.toml
file, containing your project settings.
Inside thefly.toml
file, ensure the service’sinternal_port
(8080 by default) matches the port exposed by your container.fly deploy
to deploy your application.fly open
to open the deployed application in your browser.
#
Cleaning up
fly destroy your-unique-app-id -y
removes your application from the Fly platform.
That’s all! Don’t forget to delete the application once you’re done testing.
The final code of this article can be found here.