Start with a brief introduction to the importance of deploying applications and APIs, and mention why Vercel is a suitable platform for this purpose.
Embark on a seamless journey from code to the cloud! In this guide, we'll unravel the magic of deploying Node.js/Express APIs seamlessly on Vercel, paired with the power of MongoDB Atlas. Elevate your projects to new heights as we navigate through the intricacies of setting up, testing locally, and finally launching your API into the cloud. Buckle up for a hands-on experience that transforms your development workflow and propels your Node.js applications into the world of effortless deployment. Let's turn your localhost endeavors into a cloud-powered success story!
1. Using the Node.js Runtime with Serverless Functions
1npm i @vercel/node
2. default dependency for express project
1npm i dotenv express mongoose
1const express = require("express");23const app = express();45require("dotenv").config();67app.use(express.json());89// ** Packages10const connectDB = require('./connection/connectToMongo');11const RestaurantModel = require("./models/book");1213connectDB()1415// ** Constant16const PORT = 5000;1718app.get('/', async (req, res) => {19res.status(200).json({20message: 'Hello World'21})22})2324app.get("/api/hello", async (req, res) => {25const list = await RestaurantModel.find();26if (list) {27res.status(200).json({ restaurant: list });28} else {29res.status(400).json({ message: "Failed To Retrieve Blogs" });30}31});3233// ** Server34app.listen(PORT, () => {35console.log(`Server is running on port http://localhost:${PORT}`)36})
Join the newsletter
Subscribe for weekly updates. No spams ever!
Copyright © 2024 | Hardik Desai | All Rights Reserved