Table of Contents
Introduction
Deploying a Serverless Node.js application to Vercel can be easily done by just adding a vercel.json configuration file to your project root directory.
Here I will show you how it can be achieved.
Please note that Vercel platform is serverless and designed for static frontends and Serverless Functions. There is no running server.
Add vercel.json file
First of all, add a vercel.json file in the root directory of your existing Node.js project. Add and commit the file to the Git repository.
{
"version": 2,
"name": "music-album",
"builds": [
{ "src": "app.js", "use": "@vercel/node" }
],
"routes": [
{ "src": "/(.*)", "dest": "/app.js" }
]
}
Create a Vercel project
-
Login Vercel.
If you don't have an account yet, you can sign up for a free account.
-
Click the "+ New Project" button on the Overview tab.
-
Import Git Repository by selecting the Git provider. GitHub, GitLab and Bitbucket are available.
-
Import Git Repository.
-
Configure the project.
- Give a Project Name.
- Click the "Deploy" button. The deployment should be triggered.
-
Check the deployment status.
-
Click the link under DOMAINS to view the application in browser.
Conclusion
Congratulations! Your Node.js application is now configured to be deployed to Vercel easily by adding a configuration file to the project.
Top comments (20)
Looking forward to doing this for several apps I currently have on Heroku but want to remove them from there. The only thing is that I also use environment variables there. How would I add them on Vercel? Because they are configured and named differently there. At least when creating a next.js app. Would that also apply with a regular Node.js app?
Hi Maria. Please note that Vercel platform is serverless and designed for static frontends and Serverless Functions.
Example of static frontend using React.js: portfolio-website-react-adafycheng...
Example of Serverless Functions using Node.js: music-album-liart.vercel.app/
Hi Ada, I got my first express transformed to Next.js app up on vercel.com! So much shorter a process. So much less code. Read to tackle my other projects! Here is the link to the live site: trump-talks-nextjs.vercel.app/ and the link to the repo: github.com/interglobalmedia/trump-...
Hi Ada. I see. I will check it out. Thanks! Because I am taking off my Node.js (no dbs) projects from Heroku and want to figure out how I can deploy them on vercel.com. But maybe then it might not be the best alternative. I will see. Thanks again for the info!
Of course. I just have to convert the apps to Next.js projects. That will be good practice! Thanks again.
Great! Just let me know the result. I'm interested to know whether Next.js application can be deployed to Next.js.
I will totally will let you know. And will even link to the live site here. Thanks again!
great~
I have deployed the node.js on the Vercel
I think you meant
vercel.json
instead ofversion.json
above? Seems to get picked up by Vercel this way. Just a small nit :) Thanks for the helpful postOh yes, you're right. Thank you for the correction! :)
everything works fine, I've this error: {
"code": "ER_ACCESS_DENIED_ERROR",
"errno": 1045,
"sqlMessage": "Access denied for user 'uj8vm0xflmhp3uve'@'3.215.23.141' (using password: YES)",
"sqlState": "28000",
"fatal": true
}
when i tried to get something. can you help?
Hi Ada,
I'm using typescript so Im guessing I have to point the filepath for build/routes towards the distribution folder? And could you explain what the difference is between the build and route configuration is?
Thanks!
Hi Kevin. For the build configuration, it allows me to run the .js files using Node.js. Without this, they are just served as plain text files. For the route configuration, I just forward all requests to the /app.js for processing.
hey @ada i was trying to deploy github.com/nightscout/cgm-remote-m... using ur tutorial but something is missing. can you help on this?
Hi Filipe. I just checked the documentation from Vercel. Please note that Vercel platform is serverless and designed for static frontends and Serverless Functions. There is no running server. That's why your application cannot run on Vercel.
My article does not emphasize this point. I'll update it. Sorry for any confusion and misleading information it may have caused.
vercel.com/guides/npm-run-start-no...
Sure, what's the problem?
Thanks for your help. I had to switch from Heroku hosting my Node.js app since their services aren't free anymore.
Great tutorial, it helped me a lot. Thanks!
Great tutorial. It helped me a lot. Thanks!
there is CORS problem with this approach can you help me about this?