Search code examples
node.jsexpressvercel

Set maximum execution time for Express on Vercel


I deployed Express.js to vercel and It works relatively well.

I used this vercel.json:

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

But my apis take long time sometimes. So I'd like to increase server execution time limit but I'm not sure how can I do it. Now, I'm on Pro plan and I know I can set maximum execution time as 60s. Thank you in advance.


Solution

  • I solved this issue by updating vercel.json like this:

    {
      "version": 2,
      "functions": {
        "api/**/*.js": {
          "maxDuration": 60
        }
      },
      "rewrites": [
        {
          "source": "/(.*)",
          "destination": "/api"
        }
      ]
    }
    

    My entry point index.js file is in /api directory and other js files are in /src directory. Originally, there were together in /api and my express app just returns source code of index.js. After I move other js files to another directory, it worked fine.