Deploying Your Node.js Application with Coolify: A Step-by-Step Guide

August 20, 2024 (4mo ago)

Deploying a Node.js application can sometimes be a complex task, but with the right tools, it can be streamlined and straightforward. Coolify is an open-source, self-hosted platform that makes it easy to deploy applications, including Node.js apps. In this guide, we'll walk through the steps to deploy a Node.js application using Coolify.

Prerequisites

Before we start, make sure you have the following:

  1. A Node.js application ready to deploy.
  2. A server or local machine with Docker installed.
  3. Coolify installed on your server. (If you don't have Coolify installed, follow the Coolify installation guide.)

Step 1: Prepare Your Node.js Application

Ensure your Node.js application is ready for deployment. Your application should have the following:

# Use the official Node.js image.
FROM node:14
 
# Create and change to the app directory.
WORKDIR /usr/src/app
 
# Copy application dependency manifests to the container image.
COPY package*.json ./
 
# Install dependencies.
RUN npm install
 
# Copy local code to the container image.
COPY . .
 
# Expose the port your app runs on.
EXPOSE 3000
 
# Run the web service on container startup.
CMD ["npm", "start"]

Step 2: Push Your Code to a Repository

Push your Node.js application code to a Git repository (GitHub, GitLab, or any other Git service). Coolify will pull the code from this repository during deployment.

Step 3: Set Up Coolify

  1. Log in to Coolify: Open your browser and navigate to your Coolify dashboard.

  2. Add a New Application:

    • Click on the "Add Application" button.
    • Choose "Node.js" as the application type.
    • Provide a name for your application.
    • Select the Git provider (GitHub, GitLab, etc.) and authenticate if necessary.
    • Select the repository and branch where your Node.js application code is stored.
  3. Configure the Build:

    • In the build settings, you can specify the build command and start command if they are different from the default (npm install and npm start respectively).
    • Choose the Dockerfile path if it is not in the root directory.
  4. Environment Variables:

    • Add any necessary environment variables for your application. These can include variables like NODE_ENV, DATABASE_URL, etc.
  5. Set Up Domains and SSL (Optional):

    • If you want your application to be accessible via a custom domain, you can set up the domain and SSL in the Coolify interface.

Step 4: Deploy Your Application

Once everything is configured, click on the "Deploy" button. Coolify will:

  1. Pull the code from your repository.
  2. Build the Docker image using the Dockerfile.
  3. Deploy the containerized application.

You can monitor the deployment logs in the Coolify dashboard to ensure everything is working correctly.

Step 5: Access Your Application

After the deployment is complete, Coolify will provide you with a URL to access your Node.js application. If you've set up a custom domain, you can access your application via that domain.

Conclusion

Deploying a Node.js application with Coolify is a straightforward process that leverages Docker for containerization and provides a user-friendly interface for managing deployments. By following the steps outlined in this guide, you can have your Node.js application up and running on Coolify in no time. Happy deploying!


Feel free to reach out if you have any questions or need further assistance with your deployment.