DEV Community

Cover image for Deploy Express.js app to Vercel
Ha Tuan Em
Ha Tuan Em

Posted on • Updated on

Deploy Express.js app to Vercel

After research how to deploy Express.js app to Vercel. Finally, I found and got have an application has deployed to Vercel. It's take a lot of time from me but I am happy and hope this article will help something to you.

I. First of all, creating new Github repository and init new project nodejs.

Clone and init project

II. Creating new project in Vercel

image

III. Installing package express to nodejs app.

install express package

IV. Creating and endpoint file index.js in root source.

Creating index.js file

V. Creating APIs in ./api folder or you can rename anything which you like.

  • Here is an example for manage product from ./api/product.

API folder

VI. Testing before commit source to Github.

Testing

  • After testing is 👌. Commit them to git to see something awesome.

VII. Ready to serve in Vercel.

image

VIII. Something went wrong in Vercel.

image

  • Because Vercel just supports API from Framework JS as NEXT.JS, Nuxt.JS,... So if we develop a standalone application we need to configure or tell the server of Vercel how is it work by vercel.json file.

IX. Add new vercel.json file to root source.

  • Commit it to GitHub and make sure version is 2 - this is required from Vercel.

Vercel.json file

X. Done, enjoy your moment.

Thanks for reading.
And I hope something good to you.
Here is repository which use in this post.


Buy me a coffee

XI. Or you can follow this tutorial in youtube.

Top comments (25)

Collapse
 
catur profile image
Catur Wicaksono

this is awesome.. but when i try to build using express generator, it doesn't work, is there any help :(

Collapse
 
hte305 profile image
Ha Tuan Em

Vercel is not supporting the Express Generator at the moment. Becasue it's attach to the pattern of serverless. Instead, you can use express traditional. Thanks.

Collapse
 
mohaymenrafi profile image
mohaymen_rafi

Thanks!

Collapse
 
latze profile image
latze

So i created an api with express
can i use vercel to deploy it?

Collapse
 
hte305 profile image
Ha Tuan Em

Yes, you can.

Collapse
 
erfelipee profile image
Felipe

Thanks!

Collapse
 
jdgamble555 profile image
Jonathan Gamble

Could you show us how to do this with Angular Universal or NestJS?

Collapse
 
hte305 profile image
Ha Tuan Em

I will try it.

Collapse
 
sh20raj profile image
Sh Raj • Edited
{
    "version": 2,
    "builds": [
      {
        "src": "server.js",
        "use": "@vercel/node"
      }
    ],
    "routes": [
      {
        "src": "/(.*)",
        "dest": "/"
      }
    ]
  }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
thechallengerr profile image
thechallengerr

But how can I deploy a express - handlebars to vercel ? Here is my folder structure and vercel.json :

Image description

"builds": [
        {
            "src": "src/*.js",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "./src/routes/index.js"
        }
    ]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ajmirsarker profile image
Arafat

have you got any answer?

Collapse
 
samx23 profile image
Sami Kalammallah

How about a full stack app where I use express on folder /server and react on /client ?

Collapse
 
hte305 profile image
Ha Tuan Em

Waiting for my new post 😀

Collapse
 
barhoumimohamedali profile image
Barhoumimohamedali

thanks , this is really useful!

Collapse
 
sidtalesara profile image
sid-talesara

Thanks man. I was stuck in last step and this helped me a lot.

Collapse
 
kpripper profile image
kpripper

Your app doesn't work express-vercel-theta.vercel.app
Cannot GET /

Collapse
 
khalby786 profile image
khaleel gibran

This is really great, but isn't that the whole point of serverless functions?

Collapse
 
hte305 profile image
Ha Tuan Em

Actually, Express is a traditional server. It's not supported by serverless. But you still want to covert Express to serverless app. You can find out in this article. But I recommend you should using Next.js to making an awesome application with full serverless function.
Thanks =)

Collapse
 
fecocode profile image
Feco

Thanks @hte305 !

Collapse
 
hte305 profile image
Ha Tuan Em

Hope, it helps something to you.

Collapse
 
kamalhossain profile image
Kamal Hossain

Is it completely free?

Collapse
 
hte305 profile image
Ha Tuan Em • Edited

As you wish 😉

Collapse
 
kbcruz6 profile image
Agustin Cruz

Hi ! I am having an issue, I can see my express app (which has front too) in localhost successfully, but when i deploy it in vercel, I cannot see the app, what should i do?}
ThankS!