When using Serverless Functions, you may wish to include files at runtime. Given the serverless nature of the Vercel platform, this is handled differently than in a traditional running server environment.

Node.js

To import files at runtime in a Node.js Serverless Function, create a vercel.json file and include the following configuration:

{
  "functions": {
    "api/hello.js": {
      "includeFiles": "_files/**"
    }
  }
}

An example vercel.json file that imports files into Serverless Functions at runtime.

You can the edit the api/hello.js Serverless Function to use the imported files like so:

const { readFileSync } = require('fs')
const { join } = require('path')
const file = readFileSync(join(__dirname, '_files', 'ci.yml'), 'utf8')

An example Serverless Function that reads from the filesystem.

For further information, please refer to the advanced Node.js usage section in the Vercel documentation.

Next.js

At present, it is not possible to import files in a Next.js SSR page or function given this issue.