Skip to content
Firefly Plus
Docs menu
Docs / Start

Example: Node.js

A small Node.js web app, its Dockerfile, and how to deploy it.

A web app in plain Node.js, with no dependencies. It answers on the port in PORT, which we set for each instance.

The app

server.js:

// A minimal web app: it answers on the port in PORT, which the platform sets.
const http = require('node:http');

const port = Number(process.env.PORT) || 8080;

http
    .createServer((req, res) => {
        res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
        res.end('Hello from Node.js\n');
    })
    .listen(port, () => console.log(`listening on ${port}`));

package.json:

{
    "name": "hello-node",
    "private": true,
    "scripts": { "start": "node server.js" }
}

The Dockerfile

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY package*.json ./
RUN npm install --omit=dev
COPY . .
USER node
CMD ["node", "server.js"]

It installs only production dependencies and runs as the image’s node user, not as root. Add a .dockerignore with node_modules in it, so your local packages aren’t copied in.

Deploy it

You can deploy it two ways.

From GitHub

  1. Put these files in a repository on GitHub.
  2. In the dashboard, choose Create app, name it, and choose GitHub repository as its source. Pick the repository and branch.
  3. Keep the web process’s Port at 8080, or any port you like: your app reads it from PORT.
  4. Choose Create app. It builds your Dockerfile and deploys; every push to the branch does it again.

From an image you build

  1. Build the image for 64-bit Linux, and push it to a registry you use, such as Docker Hub or GitHub’s:

    docker build --platform linux/amd64 -t ghcr.io/you/hello-node:1 .
    docker push ghcr.io/you/hello-node:1
  2. Choose Create app, name it, choose Container image, and enter the image in Image.

  3. Keep the web process’s Port at 8080, and choose Create app.

Check it

Once its deploy succeeds, open https://hello-node.fireflyplus.site. It says:

Hello from Node.js

Something unclear? Email support@firefly.plus.