How to deploy nodejs based server to vercel.com that contains express router

I have created NodeJS based app that when you upload a image, and submit it, it make post request and turns you an object like that

{"name":"MEHMET SAYIN CV - 10_2021.pdf","type":"application/pdf","size":99771}

It is working in localhost well. But I wanted to deploy it in vercel.com to make the server public. I added the now.json file to the main directory. It includes these codes.

{
    "version": 2,
    "builds": [
        {
            "src": "./server.js",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "/"
        }
    ]
}

This is a picture from my directories. enter image description here
So when I deploy my app to vercel via github,it is not working. I dont know if I am missing sth in my now.json file.

I have never deployed anything else on Vercel other than Next, but I am not even 100% sure you can deploy a standalone express server to it.

I know that you can use an express server as part of the serverless functions as stated here:

So my question to you is: are you sure you can host a standalone Node server in Vercel?

@Marmiz Yes, you can. Take a look at this essay. Deploy Express.js app to Vercel - DEV Community It is explaining how to do it .I didn’t want to deploy it to Heroku due to it restrict me to only 5 projects. I couldn’t deploy more than 5 projects. So I want to choose it actually

That blog post tells you exactly to do what Vercel describe as a Serverless API:

The project needs to live in an /api folder for instance.
On the other hand seems your api are living inside a route folder.

Moreover that article is talking about a vercel.json file, while you mention a now.json.

Anyway I am still not 100% sold that the above will create an app instance.
It’s still possible that Vercel will deploy it as a serverless function.

[EDIT]
Regardless of the implication of the architectural difference that you may or may not care about, I would still follow the official Vercel documentation.

@Marmiz I also looked on documentation, I could not found details on it. But I also changed the points you mentioned. I used verce.json file and changed api folder directory again. It is working in local. Take a look.
https://github.com/sayinmehmet47/boilerplate-project-filemetadata

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.