Is it possible to deploy a NodeJs app in Vercel?

前端 未结 3 585
南旧
南旧 2021-02-02 15:34

I\'m trying to deploy an API (made in Node) at Vercel (https://vercel.com, before Now) from the CLI. But when I deploy the app, I open the site and the result is just the files

相关标签:
3条回答
  • 2021-02-02 16:04

    You should look at https://github.com/Chuloo/now-express repository for their serverless boilerplate code

    0 讨论(0)
  • 2021-02-02 16:05

    Run yarn global add now@latest to install the CLI

    1. Create a now.json file and paste this
    {
      "version": 2,
      "builds": [{
        "src": "./server.js",
        "use": "@now/node-server"
      }],
      "routes": [{"handle": "filesystem"},
        {
          "src": "/.*",
          "dest": "server.js"
        }
      ]
    }
    
    

    Note: Change "src": "server.js", && "dest":"server.js" to your server entry file.

    1. Add it to .gitignore

    2. Then run now in the CLI to deploy.

    If you are deploying to production use now --prod command in the CLI to deploy

    Here is an example server that I deployed: https://vercel-example-server.now.sh.

    0 讨论(0)
  • 2021-02-02 16:23

    For the time being, with Vercel it's not possible to have a server-run web app that relies on Node.

    Vercel is a cloud platform for static frontends and serverless functions.

    In order to deploy a node api with Vercel you would need to use their serverless functions.

    0 讨论(0)
提交回复
热议问题