{"id":22158869,"url":"https://github.com/jlarmstrongiv/create-vercel-http-server-handler","last_synced_at":"2026-04-10T07:02:57.207Z","repository":{"id":45565804,"uuid":"305017481","full_name":"jlarmstrongiv/create-vercel-http-server-handler","owner":"jlarmstrongiv","description":"The definitive guide to running servers in Vercel.","archived":false,"fork":false,"pushed_at":"2023-12-15T17:32:39.000Z","size":352,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-26T17:26:13.727Z","etag":null,"topics":["expressjs","nextjs","nodejs","vercel","vercel-serverless"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/create-vercel-http-server-handler","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlarmstrongiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-18T03:53:03.000Z","updated_at":"2021-02-02T18:16:09.000Z","dependencies_parsed_at":"2023-12-15T18:44:14.703Z","dependency_job_id":null,"html_url":"https://github.com/jlarmstrongiv/create-vercel-http-server-handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jlarmstrongiv/create-vercel-http-server-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Fcreate-vercel-http-server-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Fcreate-vercel-http-server-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Fcreate-vercel-http-server-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Fcreate-vercel-http-server-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlarmstrongiv","download_url":"https://codeload.github.com/jlarmstrongiv/create-vercel-http-server-handler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlarmstrongiv%2Fcreate-vercel-http-server-handler/sbom","scorecard":{"id":523002,"data":{"date":"2025-08-11","repo":{"name":"github.com/jlarmstrongiv/create-vercel-http-server-handler","commit":"1d92ac6e2b55d5d5564df9ac1c5a5b327a489d14"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"93 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-cj7v-w2c7-cp7c","Warn: Project is vulnerable to: GHSA-4jpv-8r57-pv7j","Warn: Project is vulnerable to: GHSA-c2jc-4fpr-4vhg","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x","Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-7gc6-qh9x-w6h8","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-wm7h-9275-46v2","Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w","Warn: Project is vulnerable to: GHSA-434g-2637-qmqr","Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m","Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw","Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p","Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747","Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq","Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488","Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-44fp-w29j-9vj5","Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-vxf5-wxwp-m7g9","Warn: Project is vulnerable to: GHSA-9gr3-7897-pp7m","Warn: Project is vulnerable to: GHSA-25mp-g6fv-mqxx","Warn: Project is vulnerable to: GHSA-fmvm-x8mv-47mj","Warn: Project is vulnerable to: GHSA-c59h-r6p8-q9wc","Warn: Project is vulnerable to: GHSA-g77x-44xx-532m","Warn: Project is vulnerable to: GHSA-7gfc-8cq8-jh5f","Warn: Project is vulnerable to: GHSA-qpjv-v59x-3qc4","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-h7cp-r72f-jxh6","Warn: Project is vulnerable to: GHSA-v62p-rq8g-8h59","Warn: Project is vulnerable to: GHSA-566m-qj78-rww5","Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3","Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx","Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-gp95-ppv5-3jc5","Warn: Project is vulnerable to: GHSA-54xq-cgqr-rpm3","Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7","Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6","Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj","Warn: Project is vulnerable to: GHSA-wpg7-2c88-r8xv","Warn: Project is vulnerable to: GHSA-pq67-2wwv-3xjx","Warn: Project is vulnerable to: GHSA-8cj5-5rvv-wf4v","Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T03:32:37.712Z","repository_id":45565804,"created_at":"2025-08-20T03:32:37.712Z","updated_at":"2025-08-20T03:32:37.712Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019343,"owners_count":26086711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expressjs","nextjs","nodejs","vercel","vercel-serverless"],"created_at":"2024-12-02T03:39:05.204Z","updated_at":"2025-10-14T15:42:05.299Z","avatar_url":"https://github.com/jlarmstrongiv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The definitive guide to running servers in Vercel\n\n### Versel’s Philosophy\n\n\u003e It's possible to deploy an Express.js application as a single Serverless Function, but it comes with drawbacks and should only be used as a migration path. Instead, embrace multiple Serverless Functions as you incrementally migrate to the Vercel platform.\n\n### My Philosophy\n\nWhile there are cases where following Vercel’s approach is beneficial, I disagree with entirely dismissing these frameworks. With frameworks like Express.js and Nest.js, I can:\n\n- keep my application portable among hosting providers (**_No vendor locking_**)\n- take advantage of the enormouse ecosystem of existing packages, tools, and features built around these frameworks, without reinventing the wheel each time (**_DRY_**)\n- reference many resources to learn, build, and bug fix my application in a large community (**_many resources_**)\n\nThe main drawback† is a slightly longer cold start time when initializing the framework and risking the 50MB limit. This package caches your server so this delay will not be an issue in subsequent requests.\n\n## Use cases\n\nThis package has three main helper functions:\n\n- createNextHandler (expessjs and nestjs)\n- createVercelHandler (nestjs)\n- createLambdaHandler (nestjs)\n\n## Next.js\n\n### Install\n\nThis quick start assumes you bootstrapped your function with `npx create-next-app project-name`. However, this package should work with any [Zero Config Deployments](https://vercel.com/blog/zero-config).\n\nInstall this package via [npm](https://www.npmjs.com/package/create-vercel-http-server-handler),\n`npm install create-vercel-http-server-handler`\n\nBe sure you have installed the dependencies of your framework in your project, as this package relies on them.\n\nFor Express, `npm install express`\n\nFor Nest.js, `npm install @nestjs/core @nestjs/common @nestjs/platform-express`\n\n### Setup\n\nInside your api folder, create a [catch all API route](https://nextjs.org/docs/api-routes/dynamic-api-routes#catch-all-api-routes). For example, make a file named `[...slug].ts`. Inside that file, import this package:\n\n```ts\nimport {\n  createNextHandler,\n  bootstrapExpress,\n  bootstrapNest,\n} from 'create-vercel-http-server-handler';\n```\n\nExport default the handler helper for your framework of choice, and disable the bodyParser.\n\n**Express.js**\n\n```ts\nexport default createNextHandler({\n  bootstrap: bootstrapExpress({ app }),\n});\n\nexport const config = {\n  api: {\n    bodyParser: false,\n  },\n};\n```\n\n**Nest.js**\n\nThis package expects you to use the default [`@nestjs/platform-express`](https://www.npmjs.com/package/@nestjs/platform-express) under the hood. It will not work with [`@nestjs/platform-fastify`](https://www.npmjs.com/package/@nestjs/platform-fastify). Check out the example on [github](https://github.com/jlarmstrongiv/next-with-nest-graphql).\n\nWhen using typescript, don’t forget to `npm install --save-dev typescript @types/react @types/node`\n\nOptionally, create a `useGlobal` function for Nest.js to apply any global prefixes, pipes, filters, guards, and interceptors. Because Next.js api routes are all prefixed with `/api`, we recommend you do the same. Only start the server when invoked by the Nest.js CLI. Here is an example `src/main.ts`:\n\n```ts\nimport { NestFactory } from '@nestjs/core';\nimport { INestApplication, NestApplicationOptions } from '@nestjs/common';\nimport { AppModule } from './server/app/app.module';\n\nexport const nestApplicationOptions: NestApplicationOptions = {\n  logger: false,\n};\n\nexport async function useGlobal(app: INestApplication) {\n  app.setGlobalPrefix('/api');\n}\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  await useGlobal(app);\n  await app.listen(Number(process.env.NEST_PORT) || 3000);\n}\nif (process.env.CLI === 'NEST') {\n  bootstrap();\n}\n```\n\nPass your `AppModule` and optional `useGlobal` function to the `bootstrapNest` helper function inside your `[...slug].ts` api route.\n\n```ts\nimport {\n  createNextHandler,\n  bootstrapNest,\n} from 'create-vercel-http-server-handler';\nimport { AppModule } from '../../server/app/app.module';\nimport { useGlobal, nestApplicationOptions } from '../../main';\n\nexport default createNextHandler({\n  bootstrap: bootstrapNest({\n    AppModule,\n    useGlobal,\n    nestApplicationOptions,\n  }),\n  NODE_ENV: process.env.NODE_ENV,\n  NEST_PORT: Number(process.env.NEST_PORT),\n});\n\nexport const config = {\n  api: {\n    bodyParser: false,\n  },\n};\n```\n\nNest.js also relies on experimental TypeScript features. Install the required dependencies:\n\n`npm install --save-dev @babel/plugin-transform-runtime babel-plugin-transform-typescript-metadata @babel/plugin-proposal-decorators @babel/plugin-proposal-class-properties`\n\nEnable the experimental TypeScript features with a `.babelrc` file:\n\n```json\n{\n  \"presets\": [\"next/babel\"],\n  \"plugins\": [\n    [\n      \"@babel/plugin-transform-runtime\",\n      {\n        \"regenerator\": true\n      }\n    ],\n    \"babel-plugin-transform-typescript-metadata\",\n    [\"@babel/plugin-proposal-decorators\", { \"legacy\": true }],\n    [\"@babel/plugin-proposal-class-properties\", { \"loose\": true }]\n  ]\n}\n```\n\nEdit the `tsconfig.json` for Next.js:\n\n```json\n{\n  \"compilerOptions\": {\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"baseUrl\": \"./\",\n\n    \"target\": \"es5\",\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n    \"allowJs\": true,\n    \"skipLibCheck\": true,\n    \"strict\": false,\n    \"forceConsistentCasingInFileNames\": true,\n    \"noEmit\": true,\n    \"esModuleInterop\": true,\n    \"module\": \"esnext\",\n    \"moduleResolution\": \"node\",\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n    \"jsx\": \"preserve\"\n  },\n  \"include\": [\"next-env.d.ts\", \"**/*.ts\", \"**/*.tsx\"],\n  \"exclude\": [\"node_modules\", \"dist\", \".next\", \".vercel\", \"scripts\"]\n}\n```\n\nAdd the `tsconfig.nest.json` for Nest.js:\n\n```json\n{\n  \"compilerOptions\": {\n    \"forceConsistentCasingInFileNames\": true,\n    \"esModuleInterop\": true,\n    \"moduleResolution\": \"node\",\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n\n    \"module\": \"commonjs\",\n    \"declaration\": true,\n    \"removeComments\": true,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"target\": \"es2017\",\n    \"sourceMap\": true,\n    \"outDir\": \"./dist\",\n    \"baseUrl\": \"./\",\n    \"incremental\": true\n  },\n  \"exclude\": [\"node_modules\", \"dist\", \".next\", \".vercel\", \"scripts\"]\n}\n```\n\nDon’t forget to install all of Nest.js’ dependencies and dev dependencies. Plus, move relevant scripts, configs, .gitignores, and other files. Consider moving all the server files into `src/server/*` and moving the `main.ts` into `src/main.ts`.\n\n`npm install @nestjs/common @nestjs/core @nestjs/platform-express reflect-metadata rimraf rxjs`\n\n`npm install --save-dev @nestjs/cli @nestjs/schematics @nestjs/testing @types/express @types/jest @types/node @types/supertest @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-import jest prettier supertest ts-jest ts-loader ts-node tsconfig-paths typescript`\n\nUpdate the `nest-cli.json` to reflect the new organization:\n\n```json\n{\n  \"collection\": \"@nestjs/schematics\",\n  \"sourceRoot\": \"src/server\",\n  \"compilerOptions\": {\n    \"plugins\": [\"@nestjs/graphql/plugin\"]\n  }\n}\n```\n\nFinally, update the scripts inside the `package.json` and install the required script dependencies:\n\n`npm install --save-dev npm-run-all cross-env wait-on`\n\n```json\n{\n  \"scripts\": {\n    \"predev\": \"rimraf dist\",\n    \"dev\": \"npm-run-all -p -r dev:nest dev:next:wait\",\n    \"dev:next\": \"cross-env NEST_PORT=7000 next dev -p 8000\",\n    \"dev:next:wait\": \"npm-run-all -s dev:nest:wait dev:next\",\n    \"dev:nest\": \"cross-env NEST_PORT=7000 CLI=NEST nest start --path ./tsconfig.nest.json --watch --preserveWatchOutput\",\n    \"dev:nest:wait\": \"wait-on tcp:7000\",\n    \"build\": \"npm run build:next\",\n    \"build:next\": \"next build\",\n    \"prebuild:nest\": \"rimraf dist\",\n    \"build:nest\": \"cross-env NODE_ENV=production nest build --path ./tsconfig.nest.json\",\n    \"start\": \"npm run start:next\",\n    \"start:next\": \"next start -p 8000\",\n    \"start:nest\": \"cross-env CLI=NEST NEST_PORT=7000 nest start --path ./tsconfig.nest.json\",\n    \"start:nest:prod\": \"cross-env CLI=NEST NEST_PORT=7000 node dist/main\",\n    \"lint\": \"eslint \\\"{src,apps,libs,test}/**/*.ts\\\" --fix\",\n    \"test\": \"jest\",\n    \"test:watch\": \"jest --watch\",\n    \"test:cov\": \"jest --coverage\",\n    \"test:debug\": \"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand\",\n    \"test:e2e\": \"jest --config ./test/jest-e2e.json\"\n  }\n}\n```\n\nIf you are using graphql, customize the webpack config in `next.config.js` and `npm install --save-dev ts-loader`:\n\n```js\nmodule.exports = {\n  webpack: (config, { isServer }) =\u003e {\n    if (isServer) {\n      const tsLoader = {\n        test: /\\.tsx?$/,\n        loader: 'ts-loader',\n        options: {\n          transpileOnly: true,\n          getCustomTransformers: program =\u003e ({\n            before: [require('@nestjs/graphql/plugin').before({}, program)],\n          }),\n        },\n        exclude: /node_modules/,\n      };\n      config.module.rules.push(tsLoader);\n    }\n    return config;\n  },\n};\n```\n\nIf you are creating custom scripts, you will need another `tsconfig.scripts.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"noEmit\": true,\n\n    \"forceConsistentCasingInFileNames\": true,\n    \"esModuleInterop\": true,\n    \"moduleResolution\": \"node\",\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n\n    \"module\": \"commonjs\",\n    \"declaration\": true,\n    \"removeComments\": true,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"target\": \"es2017\",\n    \"sourceMap\": true,\n    \"baseUrl\": \"./\",\n    \"incremental\": true\n  },\n  \"exclude\": [\"node_modules\", \"dist\", \".next\", \".vercel\"]\n}\n```\n\n### Serverless Configuration\n\nFor additional configuration, read Vercel’s [docs](https://vercel.com/docs/configuration#project/functions).\n\n**vercel.json**\n\n```json\n{\n  \"version\": 2,\n  \"scope\": \"your-scope\",\n  \"functions\": {\n    \"src/pages/api/[...slug].ts\": {\n      \"memory\": 3008,\n      \"maxDuration\": 60\n    }\n  }\n}\n```\n\n### How it works\n\nThe first argument of `createNextHandler` is your bootstrap function. The second argument is `enableCache` to cache your server after startup. I recommend using `!!process.env.AWS_REGION` so that your server is cached on Vercel hosting, but will still hot reload properly locally.\n\nInternally, we call `http.createServer(expressApp)` and cache your server after calling `app.listen(port, () =\u003e { … });`. We proxy your server by forwarding all of Vercel’s requests via `node-http-proxy`. Essentially, we are running a server inside a serverless function.\n\n## AWS Lambda\n\n### Install\n\nThis QuickStart assumes you bootstrapped your function with `nest new project-name`. However, this package should work with any [Zero Config Deployments](https://vercel.com/blog/zero-config).\n\nInstall this package via [npm](https://www.npmjs.com/package/create-vercel-http-server-handler), `npm install create-vercel-http-server-handler`\n\nBe sure you have installed the dependencies of your framework in your project, as this package relies on them.\n\nFor express, `npm install aws-serverless-express @nestjs/platform-express`\n\nFor claudia, `npm install claudia --save-dev`\n\n### TypeScript\n\nEdit your `tsconfig.json` file:\n\n```json\n{\n  \"compilerOptions\": {\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n    \"skipLibCheck\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"esModuleInterop\": true,\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n\n    \"module\": \"commonjs\",\n    \"declaration\": true,\n    \"removeComments\": true,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"target\": \"es2017\",\n    \"sourceMap\": true,\n    \"outDir\": \"./dist\",\n    \"baseUrl\": \"./\",\n    \"incremental\": true\n  }\n}\n```\n\n### Setup\n\nInside your source folder, extract all your global app settings into `src/useGlobal.ts`:\n\n```tsx\nimport helmet from 'helmet'; // npm i helmet\nimport { UseGlobal } from 'create-vercel-http-server-handler';\n\nexport const useGlobal: UseGlobal = async app =\u003e {\n  app.use(helmet());\n  app.enableCors();\n\n  // only exists in NestExpressApplication\n  if ('disable' in app) app.disable('x-powered-by');\n\n  return app;\n};\n```\n\nRefactor your `src/main.ts` to use the `useGlobal.ts` function:\n\n```tsx\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app/app.module';\nimport { useGlobal } from './useGlobal';\n\nasync function start() {\n  const app = await NestFactory.create(AppModule);\n  await useGlobal(app);\n  await app.listen(4000);\n}\nstart();\n```\n\nCreate your `src/lambda.ts` file:\n\n```tsx\nimport { createLambdaHandler } from 'create-vercel-http-server-handler';\nimport { AppModule } from './app/app.module';\nimport { useGlobal } from './useGlobal';\n\nmodule.exports.handler = createLambdaHandler({\n  AppModule,\n  useGlobal,\n});\n```\n\n### Claudia.js\n\nWe will deploy our function with Claudia.js. Be sure to follow their setup [instructions](https://claudiajs.com/tutorials/installing.html).\n\nUnfortunately, Claudia.js does not support native modules (which are c++ libraries built for specific NodeJS versions and operating systems), like sharp.js. We will adapt steps from this [guide](https://cuneyt.aliustaoglu.biz/en/using-docker-and-claudia-js-to-deploy-lambda-functions/) to script our own support. Be sure you have docker [installed](https://www.docker.com/get-started).\n\n#### Scripts\n\nInside `project-name/scripts/claudia-create.sh`:\n\n```bash\ndocker run -v $PWD:/claudia -v $HOME/.aws:/root/.aws --rm lambci/lambda:build-nodejs12.x /bin/bash -c \"\\\ncd /claudia\nrm -rf node_modules\nnpm install\nnpm run build\nnpm run claudia-create\n\"\n```\n\nInside `project-name/scripts/claudia-update.sh`:\n\n```bash\ndocker run -v $PWD:/claudia -v $HOME/.aws:/root/.aws --rm lambci/lambda:build-nodejs12.x /bin/bash -c \"\\\ncd /claudia\nrm -rf node_modules\nnpm install\nnpm run build\nnpm run claudia-update\n\"\n```\n\nMake the scripts executable by running `chmod +x ./scripts/claudia-create.sh` and `chmod +x ./scripts/claudia-update.sh` in your terminal. You should only need to do this once.\n\nAdd these scripts to your `package.json`:\n\n```json\n{\n  \"claudia-create\": \"claudia create --handler dist/lambda.handler --deploy-proxy-api --region us-east-1 --timeout 29\",\n  \"claudia-update\": \"claudia update --timeout 29\",\n  \"create\": \"./scripts/claudia-create.sh\",\n  \"update\": \"./scripts/claudia-update.sh\"\n}\n```\n\nTo run Nest.js locally again, be sure to reinstall your dependencies with `npx rimraf node_modules` and `npm install`. You will need to do this after every deployment.\n\nFinally, you will need to add these fields to your `package.json` for Claudia.js to [behave](https://github.com/claudiajs/claudia/issues/132#issuecomment-364757470) correctly:\n\n```json\n{\n  \"files\": [\"dist\"],\n  \"main\": \"lambda.js\"\n}\n```\n\nor\n\n```json\n{\n  \"main\": \"dist/lambda.js\"\n}\n```\n\n#### Avoiding the 50MB limit\n\nNo matter what, claudiajs will always [include](https://claudiajs.com/tutorials/packaging.html#dependent-libraries) your production dependencies in your `node_modules` folder. However, there are often [unnecessary files](https://web.archive.org/web/20191130051804/https://miro.medium.com/max/1916/1*DzW3ZKDzODwEawxzXSzimg.png) included with your package.\n\nTo avoid hitting the 50MB limit, use a package to prune the `node_modules` folder using:\n\n- https://www.npmjs.com/package/modclean\n- https://www.npmjs.com/package/node-prune\n\n##### Modclean\n\nRun `npm install modclean --save-dev`\n\nAdd a postinstall script to your `package.json`:\n\n```json\n{\n  \"postinstall\": \"npx modclean -n default:caution --no-progress --run\"\n}\n```\n\nInside your docker scripts, add `npm set unsafe-perm true` before running any npm commands to fix the `cannot run in wd` error.\n\n## Vercel Serverless\n\nThis QuickStart assumes you bootstrapped your function with `nest new project-name`. However, this package should work with any [Zero Config Deployments](https://vercel.com/blog/zero-config).\n\nInstall this package via [npm](https://www.npmjs.com/package/create-vercel-http-server-handler), `npm install create-vercel-http-server-handler` and `npm install --save-dev vercel`\n\n### **TypeScript**\n\nEdit your `tsconfig.json` file:\n\n```json\n{\n  \"compilerOptions\": {\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n    \"skipLibCheck\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"esModuleInterop\": true,\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n\n    \"module\": \"commonjs\",\n    \"declaration\": true,\n    \"removeComments\": true,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"target\": \"es2017\",\n    \"sourceMap\": true,\n    \"outDir\": \"./dist\",\n    \"baseUrl\": \"./\",\n    \"incremental\": true\n  }\n}\n```\n\n### Setup\n\nInside your source folder, extract all your global app settings into `src/useGlobal.ts`:\n\n```tsx\nimport helmet from 'helmet'; // npm i helmet\nimport { UseGlobal } from 'create-vercel-http-server-handler';\n\nexport const useGlobal: UseGlobal = async app =\u003e {\n  app.use(helmet());\n  app.enableCors();\n\n  // only exists in NestExpressApplication\n  if ('disable' in app) app.disable('x-powered-by');\n\n  return app;\n};\n```\n\nRefactor your `src/main.ts` to use the `useGlobal.ts` function:\n\n```tsx\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app/app.module';\nimport { useGlobal } from './useGlobal';\n\nasync function start() {\n  const app = await NestFactory.create(AppModule);\n  await useGlobal(app);\n  await app.listen(4000);\n}\nstart();\n```\n\nCreate your `src/vercel.ts` file:\n\n```tsx\nimport { createVercelHandler } from 'create-vercel-http-server-handler';\nimport { AppModule } from './app/app.module';\nimport { useGlobal } from './useGlobal';\n\nexport default createVercelHandler({\n  AppModule,\n  useGlobal,\n});\n```\n\n### Vercel\n\nEdit your vercel.json file:\n\n```json\n{\n  \"version\": 2,\n  \"cleanUrls\": true,\n  \"rewrites\": [\n    { \"source\": \"/api/vercel\", \"destination\": \"/api/vercel\" },\n    { \"source\": \"/\", \"destination\": \"/api/vercel\" },\n    { \"source\": \"/:match*\", \"destination\": \"/api/vercel\" }\n  ]\n}\n```\n\nNote: the root path is a bit buggy. Switch the example `@Get()` to `@Get('/hello')` in `src/app/app.controller.ts` to demo.\n\nAdd `project-name/api/vercel.js`:\n\n```jsx\nimport Handler from '../dist/vercel';\n\nexport default Handler;\n\nexport const config = {\n  api: {\n    bodyParser: false,\n  },\n};\n```\n\nRun `npx vercel` to setup and deploy your project. Choose the defaults, except for the `Output Directory` option—select `dist`, where Nestjs compiles your code (otherwise you will have an infinite loop with `npx vercel dev`).\n\nTo deploy to production, run `npx vercel --prod`. Vercel handles all native dependencies for you automatically.\n\n### Footnotes\n\n† Please note that serverless in general does not scale well when directly connecting to a database like MongoDB or PostgreSQL. Be sure you use [connection pools](https://www.digitalocean.com/docs/databases/postgresql/how-to/manage-connection-pools/#creating-a-connection-pool).\n\n## Thank you\n\nThis package would not exist without the help of:\n\n- [TSDX](https://www.npmjs.com/package/tsdx)\n- [node-http-proxy](https://www.npmjs.com/package/http-proxy)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlarmstrongiv%2Fcreate-vercel-http-server-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlarmstrongiv%2Fcreate-vercel-http-server-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlarmstrongiv%2Fcreate-vercel-http-server-handler/lists"}