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
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.
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.
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.
yarn global add now@latest
to install the CLInow.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.
Add it to .gitignore
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With