This tutorial will show you how to deploy a simple Node.js (Express) app to Vercel. Itโs perfect for beginners who want to get their API online fast โ without worrying about infrastructure.
๐งฐ Prerequisites
Before you start, make sure you have the following installed:
- โ Node.js and npm on your system
- โ Git installed
- โ GitHub account
- โ Basic knowledge of JavaScript and Node.js
๐ ๏ธ Step 1: Create a Simple Node.js App
Open your terminal and run the following commands:
mkdir my-app
cd my-app
npm init -y
npm install express
This creates a new folder, initializes a Node.js project, and installs Express.js.
๐ Step 2: Create index.js
Inside your project folder, create a file called index.js and add the following code:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello, Vercel!');
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
This sets up a basic Express server that responds with "Hello, Vercel!".
๐งช Step 3: Test the App Locally
Run the app locally to make sure everything works:
node index.js
Visit http://localhost:3000 in your browser โ you should see:
Hello, Vercel!
๐ Step 4: Prepare for Deployment
- Create a .gitignore file and ignore node_modules:
echo node_modules > .gitignore
- Initialize a git repository and push it to GitHub:
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
git push -u origin main
๐ Step 5: Deploy to Vercel
- Go to https://vercel.com and sign in with your GitHub account.
- Click "New Project".
- Import your repository.
- Leave all settings as default and click "Deploy".
Wait a few momentsโฆ and voilร ! Your Node.js app is live โจ
โ Conclusion
Youโve just built and deployed a Node.js app to the web using Express and Vercel. From here, you can:
- Build APIs and connect to databases
- Add frontend frameworks like React or Vue
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.