Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to deploy a NodeJs app in Vercel?

Tags:

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 in the path directory, and not the app running. This is my server.js

    {   "name": "subtitles-api",   "version": "1.0.0",   "description": "",   "main": "index.js",   "scripts": {     "start": "node server.js",     "pre-deploy": "node deleteLastDeploy.js",     "deploy": "npm run pre-deploy && now --public && now alias",     "test": "echo \"Error: no test specified\" && exit 1"   }   "engines": {     "node": ">=6.9"   },   "keywords": [],   "author": "",   "license": "MIT",   "dependencies": {     //list of dependencies   } } 

To see the full API: https://github.com/bitflix-official/subtitles-api

like image 385
NuzzeSicK Avatar asked May 14 '20 23:05

NuzzeSicK


People also ask

Does Vercel support node JS?

Use Multiple Serverless Functionsjs/Vercel give you access to the Request and Response objects from Node. js. These objects are the standard HTTP Request and Response objects from the Node. js runtime.

Can you deploy a backend on Vercel?

Additional Information. Each of your Vercel projects will get its own Thin Backend project. You can either create a new project or use an existing project from your Thin account. The integration sets the BACKEND_URL environment variable on your project.

Where can I deploy my node js app?

To deploy a Node. js application, click on the New Web Service button under the Web Services option. You can also click on the New + button displayed in the header just before your profile picture and select Web Service option.


2 Answers

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.

like image 156
Vj Abishek Avatar answered Oct 02 '22 13:10

Vj Abishek


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.

like image 37
alewis729 Avatar answered Oct 02 '22 11:10

alewis729