DEV Community

Discussion on: How to deploy a Node/Express App to Vercel

Collapse
 
nerkar_krish profile image
Krish Nerkar

how to set the port in vercel for it to know which port to serve the app on

Collapse
 
andrewbaisden profile image
Andrew Baisden

Hi I am not sure what you mean I think Vercel assigns a default port that can't be changed. However you can use whatever port you want locally.

Collapse
 
nerkar_krish profile image
Krish Nerkar

What port does it assign by default, like what should I set here app.listen(8000, ()=> {
console.log("app started")
})

Thread Thread
 
andrewbaisden profile image
Andrew Baisden • Edited

I think it uses port 3000. But regardless if you use the below it should be fine. The code process.env.PORT means that whatever is in the environment variable PORT, on Vercel's end gets assigned as the port number. Otherwise it uses 3000 or whatever port number you put there.

const port = process.env.PORT || 3000;
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
nerkar_krish profile image
Krish Nerkar

I tried it, but dosent work, just gives me a 404 page on vercel

Thread Thread
 
andrewbaisden profile image
Andrew Baisden

Hmm is your operating system Linux? Linux is not well supported by Vercel when using this method.

Thread Thread
 
nerkar_krish profile image
Krish Nerkar

Nope, I'm using plain windows, but I just can't get the app running on vercel for some reason, it's working perfectly well on localhost and even zeet.co (as you have an option to set a port to listen on) but can't figure out vercel

Do you have some github repo or anything which u can link which successfully deploys an express app to vercel

Thread Thread
 
andrewbaisden profile image
Andrew Baisden
Thread Thread
 
nerkar_krish profile image
Krish Nerkar

I checked it out and tried to recreate it but with my app, but still no success :(

here's the repo, if you can point out what mistake i am making : github.com/Krish-Nerkar/genzmafia....