Skip to content

Deploy a Node.js App

This guide explains how to deploy a Node.js application on almost any server using TurboCloud (a deployment toolkit based on Docker and Caddy Server). Whether you’re running your application on AWS, DigitalOcean, Hetzner, Scaleway or a dedicated physical server, the steps will be almost the same.

Setting Up the Server

Create a new server on your cloud provider or local machine with a public IP address, SSH access from your development machine, and a fresh Ubuntu 22.04 installation. Ensure that ports 22, 80, and 443 are open. (Some cloud providers, like AWS, close ports by default; you’ll need to open them before deployment.)

If you’re looking for a new cloud provider, consider Hetzner, DigitalOcean, or OVH. These providers typically have ports open by default. OVH also offers affordable domain registration and free DNS management via API.

Prepare Your Node.js App for Deployment

If you deploy with TurboCloud, it will check for the presence of a Dockerfile in the project's root directory. We recommend creating a Dockerfile manually and placing it in the project's root folder for better control:

  • Create a file named Dockerfile in your project’s root directory with the following content (change node:20.9.0-bullseye-slim if you need another Node.js version and change CMD ["dumb-init", "node", "index.js"] if your Node.js should be started with another js file - for example, CMD ["dumb-init", "node", "server.js"] ):
#The build image
FROM node:latest AS build
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN --mount=type=secret,mode=0644,id=npmrc,target=/usr/src/app/.npmrc npm ci --only=production

#The production image
FROM node:20.9.0-bullseye-slim
ENV NODE_ENV production
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
USER node
WORKDIR /usr/src/app
COPY --chown=node:node --from=build /usr/src/app/node_modules /usr/src/app/node_modules
COPY --chown=node:node . /usr/src/app
CMD ["dumb-init", "node", "server.js"]

Deploy from the Local Repository

  • On your development machine, navigate to the folder containing the project's code and run the deployment command (replace server_ip with the actual public IP of your server and service_port with the port number your app uses):
cd my_project
curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p service_port
  • Wait until the deployment script displays the URL of the deployed Node.js application.
  • Full documentation for all available parameters and detailed instructions can be found at turbocloud.dev/docs.

Deploy from GitHub or Bitbucket

  • SSH into your server (replace server_ip with the actual public IP of your server):
ssh root@server_ip
  • Run the setup command:
curl https://turbocloud.dev/setup | bash -s
  • Once installation is complete, start the TurboCloud TUI (Terminal User Interface), which functions similarly to standard applications on macOS, Linux, and other operating systems but can operate on servers without displays. Use the TUI to set up deployments with interactive guides:
turbocloud