How to Deploy a Serverless Node.js Express App with ZEIT Now Vercel Cloud Platform Full Tutorial

You are currently viewing How to Deploy a Serverless Node.js Express App with ZEIT Now Vercel Cloud Platform Full Tutorial

Welcome folks today in this tutorial we will be deploying a serverless express node.js application to zeit now vercel cloud platform from scratch. All the step by step instructions are given below. Also a step by step youtube video is also shown below.

 

 

Installation

 

First of all you need to globally install the now cli inside your system so that you can upload your projects. Head over to cmd and execute the below command as follows.

npm install -g now

 

Now after that head over to a new directory initialize a empty node.js express project create the package.json file like this

 

Now create the index.js in the root directory of your node project and copy paste the following code into it

const express = require("express");
const app = express();

const port = 5000;

// Listen on port 5000
app.listen(port, () => {
  console.log(`Server is booming on port 5000
Visit http://localhost:5000`);
});

 

 

Now make a simple home route and copy paste the below code into index.js

app.get('/',(req,res) => {
    res.send("This is a sample express app")
})

 

 

Deploying Application Using Now

 

 

As you can see we have got the error we need to create this vercel.json file which is necessary for the deployment of the project.

Create this vercel.json inside the root directory of your project and copy paste the code given below.

{
  "version": 2,
  "builds": [{ "src": "index.js", "use": "@now/node-server" }],
}

 

Leave a Reply