GitHub Actions for Node.js — Deploy to Vercel

Sanjeev SharmaSanjeev Sharma
2 min read

Advertisement

GitHub Actions for Node.js — Deploy to Vercel

Build and deploy Node.js applications using GitHub Actions with automated testing and Vercel deployment.

Introduction

GitHub Actions simplifies Node.js development workflows with testing, building, and automated deployment.

Node.js Testing

name: Node.js CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [16.x, 18.x, 20.x]
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: npm run lint
    - run: npm test
    - run: npm run build

Coverage Reports

- name: Run tests with coverage
  run: npm test -- --coverage
- name: Upload coverage
  uses: codecov/codecov-action@v3
  with:
    files: ./coverage/lcov.info

Vercel Deployment

name: Deploy to Vercel

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: '18'
    - run: npm ci
    - run: npm run build
    - name: Deploy to Vercel
      uses: vercel/action@master
      with:
        vercel-token: ${{ secrets.VERCEL_TOKEN }}
        vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
        vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}

FAQ

Q: How do I get Vercel tokens? A: From Vercel dashboard → Settings → Tokens

Q: Can I deploy previews on PRs? A: Yes, Vercel automatically creates preview URLs for pull requests.

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro