Node.js Course
Node.js
/
Intermediate

CI/CD Basics

Definition

Continuous Integration and Continuous Deployment. The automated process of testing, building, and deploying code to production every time a developer commits changes to a code repository.

Explain Like I'm New

In the old days, deploying a website meant freezing development on Friday, manually running tests, FTPing files to a server, and praying nothing broke. CI/CD automates this entirely. When you `git push` to GitHub, an automated robot (like GitHub Actions) wakes up. It runs your Jest tests (CI). If they pass, it automatically logs into your AWS server, downloads the new code, and restarts PM2 (CD). You can deploy 50 times a day safely.

Real World Example

Setting up a `.github/workflows/deploy.yml` file. Every time a Pull Request is merged into the `main` branch, the code is automatically pushed live to production within 2 minutes.

Common Use Cases

  • •Automated testing
  • •Agile development
  • •Preventing human error during deployments

Terminal Output

bash / terminal
# --- EXAMPLE GITHUB ACTIONS YAML --- # name: Node.js CI/CD # # on: # push: # branches: [ main ] # # jobs: # build-and-test: # runs-on: ubuntu-latest # steps: # - uses: actions/checkout@v3 # - name: Use Node.js # uses: actions/setup-node@v3 # with: # node-version: '18.x' # - name: Install dependencies # run: npm ci # - name: Run Tests (CI Phase) # run: npm test # # deploy: # needs: build-and-test # ONLY runs if tests pass! # runs-on: ubuntu-latest # steps: # - name: Deploy to Server (CD Phase) # run: echo "Running SSH commands to pull code and restart PM2..." console.log("CI/CD turns deployment from a terrifying Friday-night ordeal into a boring, automated button click.");

Interview Questions

basic

  • What does the 'CI' stand for, and what is its main goal?

intermediate

  • What happens if a Unit Test fails during the CI pipeline?

Flash Cards

Question

What is CI?

Click to reveal answer
Answer

Continuous Integration. Its main goal is to automatically verify that new code integrates perfectly with the existing codebase by running automated tests.

Question

What if a test fails?

Click to reveal answer
Answer

The pipeline immediately aborts. The CD (Deployment) phase is blocked, preventing the buggy code from ever reaching the production server.