DEV Community

Kazi Abdur Rakib
Kazi Abdur Rakib

Posted on

How to deploy an Express API to Vercel

  1. Add vercel.json configuration After exporting Express, we have to tell Vercel what files to build, how to build them, and how to route them using a vercel.json file. So create a vercel.json file.
touch vercel.json
Enter fullscreen mode Exit fullscreen mode

Then using Vercel Platform version 2, specify your index.js file and the NPM module Vercel will use to turn it into a serverless function...

{
  "version": 2,
  "builds": [
    {
      "src": "dist/server.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "dist/server.js"
    }
  ]
}

Enter fullscreen mode Exit fullscreen mode
npm install -g vercel

Enter fullscreen mode Exit fullscreen mode
npm run build
vercel --prod
Enter fullscreen mode Exit fullscreen mode

https://shadowsmith.com/thoughts/how-to-deploy-an-express-api-to-vercel#_4-add-verceljson-configuration

Top comments (0)