Skip to content

Deploy Node.js App

What You’ll Need

  • A server with a public IP address, SSH access, and a fresh installation of Ubuntu 22.04. Not sure which cloud provider to use? Try DigitalOcean, Vultr, or Hetzner.
  • A Node.js project
  • (Optional) A custom domain

Deployment Steps

  • Create a server on your cloud provider
  • Create a Dockerfile
  • Deploy the project from a local folder or GitHub/Bitbucket

What You’ll Get

  • A deployed Node.js project without vendor lock-in
  • HTTPS with an auto-generated or custom domain
  • WAF with the default ruleset recommended by OWASP
  • Rate limiting
  • CI/CD if you deploy from GitHub or Bitbucket

Deploying a Node.js App

It doesn’t matter whether you want to deploy your Node.js app directly from your development machine or from GitHub/Bitbucket — you should create a Dockerfile before deploying:

  1. Create a Dockerfile in the project root with the following content (replace 3000 with your app’s port number. If you use yarn or another package manager, replace the RUN ... npm ci --omit=dev line accordingly):

    FROM node:lts-alpine
    # Use production node environment by default.
    ENV NODE_ENV=production
    WORKDIR /usr/src/app
    # Download dependencies as a separate step to take advantage of Docker caching.
    # Leverage a cache mount to /root/.npm to speed up subsequent builds.
    # Bind package.json and package-lock.json instead of copying them into this layer.
    RUN --mount=type=bind,source=package.json,target=package.json \
    --mount=type=bind,source=package-lock.json,target=package-lock.json \
    --mount=type=cache,target=/root/.npm \
    npm ci --omit=dev
    # Run the application as a non-root user.
    USER node
    # Copy the rest of the source files into the image.
    COPY . .
    # Expose the port that the application listens on.
    EXPOSE 3000
    # Run the application.
    CMD ["node", "src/index.js"]

Deploy a Node.js App from a Local Folder

You can deploy Node.js projects directly from a local folder on your development machine using TurboCloud:

  • If the project is a Git repository, TurboCloud uploads files tracked by Git (you can check which files will be uploaded using git ls-files --recurse-submodules). Don’t forget to add the Dockerfile with git add Dockerfile.

  • If you’re not using Git, all files inside the project folder will be uploaded.

Now everything is ready — let’s deploy:

  1. Run the command below in the root of your Node.js project (replace server_ip with your server’s actual IP and 3000 with the correct port, matching your Dockerfile):

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p 3000

    To use a custom domain, add the -d parameter (make sure your domain’s A record points to the server’s IP):

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip -p 3000 -d yourdomain.com
  2. After deployment, you’ll receive an auto-generated URL to access your site. If you specified your own domain in step 1, you can use that instead.

  3. (Optional) Visit console.turbocloud.dev to manage and monitor deployments. You can add custom domains, set up load balancing across servers, and more.

  4. To redeploy, just run the same command again:

    Terminal window
    curl https://turbocloud.dev/deploy | bash -s -- -i server_ip

Deploy a Node.js App from GitHub / Bitbucket

  1. Push the Dockerfile and all necessary changes to your Git repository (GitHub and Bitbucket are supported).

  2. SSH into a server running Ubuntu 22.04 with a public IP address, and install TurboCloud (replace server_ip with your server’s actual IP; installation takes about a minute):

    Terminal window
    ssh root@server_ip
    curl https://turbocloud.dev/setup | bash -s
  3. After installation, visit console.turbocloud.dev to add and deploy your Node.js project. In the port field, enter 3000 (or the port you configured in your Dockerfile). You can deploy projects, add custom domains, set up load balancing, and more.