-
Create an
api/restful.jsfile with the following content:require("../dist/src/main");Or create an
api/restul.tsfile with:require("../src/main"); -
Create a
vercel.jsonfile with the following content:{ "framework": null, "outputDirectory": ".", "buildCommand": "npm run build", "functions": { "api/*.js": { "memory": 1024, "maxDuration": 10 } }, "rewrites": [ { "source": "/api(.*)", "destination": "/api/restful" }, { "source": "/(.*)", "destination": "/public" } ] } -
Deploy by executing
vercel deployorvercel deploy --prod. -
Locally development:
- You can just execute
vercel dev -l 3100, which automatically loads the.envfile. You may need to runnpx nest build --watchtogether. ExecuteI founddotenv npx nest start --watchwhich manually loads the.envfile.--watchdoesn’t work in this way.- Execute
npx nest start --watchwhich needs to add the following content in your codes to load the.envfile:export const isNestDev = !process.env.JWT_SECRET; if (isNestDev) { require("dotenv").config(); }
- You can just execute
How to deploy nestjs app to vercel
Published at at 07:04 PM at 07:27 PM