Can't deploy simple NodeJS / Express server

Reproduction: GitHub - gyenabubakar/kicksdude-shopify-backend

Hi, I tried deploying a simple hello world NodeJs app but it didn’t work because I ran out of memory. I’m new to back-end development and know nothing about containerisation so I need your help to know why this is happening. Here are my logs after running fly deploy:

==> Verifying app config
Validating /Users/gyen/Desktop/CODING/~~~/fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder ~~~ ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon  59.83kB
[+] Building 13.7s (15/15) FINISHED
 => [internal] load remote build context                                                                                                                              0.0s
 => copy /context /                                                                                                                                                   0.1s
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                            0.6s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:~~~                                       0.0s
 => [internal] load metadata for docker.io/library/node:16.18.1-slim                                                                                                  0.2s
 => [base 1/2] FROM docker.io/library/node:16.18.1-slim@sha256:~~~                                       0.0s
 => CACHED [base 2/2] WORKDIR /app                                                                                                                                    0.0s
 => CACHED [build 1/6] RUN apt-get update -qq &&     apt-get install -y python pkg-config build-essential                                                             0.0s
 => [build 2/6] COPY --link package-lock.json package.json ./                                                                                                         0.0s
 => [build 3/6] RUN npm ci --include=dev                                                                                                                              4.2s
 => [build 4/6] COPY --link . .                                                                                                                                       0.0s
 => [build 5/6] RUN npm run build                                                                                                                                     5.1s
 => [build 6/6] RUN npm prune --omit=dev                                                                                                                              1.5s
 => [stage-2 1/1] COPY --from=build /app /app                                                                                                                         0.4s
 => exporting to image                                                                                                                                                0.6s
 => => exporting layers                                                                                                                                               0.6s
 => => writing image sha256:~~~                                                                          0.0s
 => => naming to registry.fly.io/~~~:deployment-~~~                                                                     0.0s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/~~~]
~~~: Pushed
~~~: Pushed
~~~: Pushed
~~~: Pushed
~~~: Pushed
~~~: Pushed
~~~: Pushed
deployment-01H~~~: digest: sha256:~~~~ size: 1785
--> Pushing image done
image: registry.fly.io/~~~~:deployment-~~~~~
image size: 246 MB

Watch your app at https://fly.io/apps/----/monitoring

Provisioning ips for -----
  Dedicated ipv6: -----
  Shared ipv4: -----
  Add a dedicated ipv4 with: fly ips allocate-v4
This deployment will:
 * create 2 "app" machines

No machines in group app, launching a new machine
  Machine -- [app] update finished: success

WARNING The app is not listening on the expected address and will not be reachable by fly-proxy.
You can fix this by configuring your app to listen on the following addresses:
  - 0.0.0.0:3000
Found these processes inside the machine with open listening sockets:
  PROCESS        | ADDRESSES
-----------------*---------------------------------------
  /.fly/hallpass | [...]:--

Creating a second machine to increase service availability
Error: error creating a new machine: failed to launch VM: To create more than 1 machine per app please add a payment method. https://fly.io/dashboard/---/billing

This is the usage stats of the Remote Builder:

Your build didn’t run out of memory, to the contrary the build succeeded.

Most node apps default to port 3000, but yours defaults to port 8080.

There are lots of ways to fix this. One is to edit fly.toml and change the 3000 you find there to 8080. Another is to add the following to your Dockerfile:

ENV PORT="8080"

A third way would be to change your application. But in the end, all that matters is that the numbers match.

1 Like

@rubys After changing the ports to 8080, I had to change the start script from "npm run build && node build/index.js" to just "node build/index.js". Now it’s running.

Thank you!