Tutorial: Run a Node App

Hello everyone,
I am a new user and I try the Run a Node App tutorial but without success.
I have clone the git repo.
The command : flyctl launch
not working for me. I get this error on Windows : “Error name argument or flag must be specified when not running interactively”
So I try manually with this command: flyctl launch --name jaribu-node -r cdg

My file fly.toml

# fly.toml file generated for jaribu-node on 2022-10-28T18:41:59+02:00

app = "jaribu-node"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

And Dockerfile :

FROM debian:bullseye as builder

ARG NODE_VERSION=16.14.2

RUN apt-get update; apt install -y curl
RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME /root/.volta
ENV PATH /root/.volta/bin:$PATH
RUN volta install node@${NODE_VERSION}

#######################################################################

RUN mkdir /app
WORKDIR /app

ENV NODE_ENV production

COPY . .

RUN npm install
FROM debian:bullseye

LABEL fly_launch_runtime="nodejs"

COPY --from=builder /root/.volta /root/.volta
COPY --from=builder /app /app

WORKDIR /app
ENV NODE_ENV production
ENV PATH /root/.volta/bin:$PATH

CMD [ "npm", "run", "start" ]

(http://jaribu-node.fly.dev) remains unavailable. What’s wrong ?

Did you deploy the code? fly deploy --dockerfile /path/to/dockerfile --region <r> --config /path/to/fly.toml (docs for node).

If so, check the status of the app and see what it tells you: fly status --all -a <app-name>.

Also, since you’re offloading tls/https to Fly’s edge proxies, expect cleartext http1 / http2 on port 8080 and handle approp (ex).

Looks like you might instead want (ref):

+ FROM node:19
- FROM debian:bullseye

How are you running this command? I’ve tried both Windows PowerShell and Command Prompt and both work for me.

1 Like

I use Cmder.
I just tried again with Powershell & cmd same issue.

Thank you very much for your help.
I modified my dockerfile:

FROM node:16-slim

WORKDIR /prod
ENV NODE_ENV production

COPY package.json /prod/package.json

RUN npm install

COPY . /prod

CMD ["node","server.js"]

EXPOSE 8080

And add in fly.toml :

[env]
  PORT = "8080"

And it’s working with the sample of git repo.
I’ll try soon with my little personal project which is on heroku.
If you see others to modify/optimize in the dockerfile or fly.toml I’m interested!

1 Like

Neat!

Dockerfile’s good (one can use webpack / turbopack / vite / rollup / astro / what-have-you to bundle up your Node app to optimize the code further, but it isn’t that big of a deal for small-to-moderately-sized apps).

You can opt to raise concurrency of this Fly app depending on the size of its VM; change services.tcp_checks.grace_period (may be, 3?); increase services.tcp_checks.timeout (may be, 5s?) / services.tcp_checks.grace_period (may be, 10s?) as approp to your app’s make-up.