DEV Community

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

Posted on • Edited 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.

Latest comments (25)

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
 
kpripper profile image
kpripper

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

Collapse
 
sidtalesara profile image
Siddharth Talesara

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

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
 
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!

Collapse
 
rst1705 profile image
MechInTech

this is awsome ,hey can i use mongodb data base for this as well

Collapse
 
letsbsocial1 profile image
Maria Campbell

I'm working on a next.js app which uses mongod and host my backend on MongoDB Atlas. Yes, you can use MongoDB. And better yet would be to use Mongoose because of its schemas.

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
 
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
 
erfelipee profile image
Felipe

Thanks!