DEV Community

Jeferson Eiji
Jeferson Eiji

Posted on • Originally published at dev.to

Step-by-Step Guide to Setting Up a CI/CD Pipeline for a Node.js Application

Setting up a CI/CD (Continuous Integration/Continuous Deployment) pipeline greatly improves development speed and code quality. Here’s a clear guide to get started with Node.js:

Steps to Set Up CI/CD for Node.js

  1. Version Control Setup

    • Use a service like GitHub, GitLab, or Bitbucket.
    • Example: Initialize git in your project folder:
    git init
    git remote add origin https://github.com/username/repo.git
    
  2. CI/CD Tool Selection

    • Common choices: GitHub Actions, GitLab CI, Jenkins, CircleCI.
    • Example: Using GitHub Actions for automation.
  3. Create Pipeline Configuration

    • Usually done with YAML files specifying steps.
    • Example (.github/workflows/nodejs.yml):
    name: Node.js CI
    on:
    push:
    branches: [ main ]
    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm install
      - run: npm test
    
  4. Testing

    • Ensure your pipeline runs tests automatically.
    • Example in the config above: npm test command.
  5. Deployment Step

    • Add deployment after tests pass.
    • Example: Deploy to Heroku or another cloud after success.
    • GitHub Actions example step:
      - name: Deploy to Heroku
        uses: akhileshns/heroku-deploy@v3.12.12
        with:
          heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
          heroku_app_name: "your-app-name"
          heroku_email: "your-email@example.com"
    

Summary

  • Automate code builds, tests, and deployments.
  • YAML files define the steps.
  • Integrate with your hosting platform for smooth deployments.

Tip: Start simple with just install, test, and deploy steps. Add more validations as your app grows.

Top comments (0)