#How do I deploy a typescript express app?
1 messages · Page 1 of 1 (latest)
The error message you're seeing indicates that the 'express' module cannot be found. This is typically due to one of the following reasons:
- The 'express' module is not installed. You can install it using npm or yarn.
- The 'express' module is not correctly imported in your code. Make sure you're using the correct syntax for importing modules in TypeScript.
However, it's important to note that deploying an Express.js application as a single Serverless Function comes with drawbacks and should only be used as a migration path. Instead, you should use Next.js or embrace multiple Serverless Functions as you incrementally migrate to the Vercel platform source (https://vercel.com/guides/using-express-with-vercel).
Also, Vercel is designed for static frontends and Serverless Functions. There is no running server. If you are trying to start a server, you are likely to run into difficulties either with your application not starting, or unexpected behavior source (https://vercel.com/guides/npm-run-start-not-working).
If you're using TypeScript, the Node.js Runtime supports files ending with .ts inside of the /api directory as TypeScript files to compile and serve when deploying source (https://vercel.com/docs/functions/serverless-functions/runtimes/node-js).
Here's an example of a serverless Node.js function written in TypeScript:
import type { VercelRequest, VercelResponse } from '@vercel/node';
export default function (request: VercelRequest, response: VercelResponse) {
const { name = 'World' } = request.query;
response.send(`Hello ${name}!`);
}
You can install the types for the Request and Response objects from npm with the following command:
npm install @vercel/node --save-dev