This is a full-stack web application built with Next.js, Node.js, and MongoDB, and deployed on Vercel. The project supports server-side rendering, API routes, and a scalable cloud database.
- Frontend: Next.js (React)
- Backend: Node.js (Next.js API Routes)
- Database: MongoDB (MongoDB Atlas)
- Deployment: Vercel
- Package Manager: npm or yarn
├── pages/
│ ├── api/ # API routes (Node.js backend)
│ ├── _app.js
│ └── index.js
├── lib/
│ └── mongodb.js # MongoDB connection helper
├── models/ # Mongoose models
├── public/ # Static assets
├── styles/ # CSS / styling
├── .env.local # Environment variables
├── package.json
└── README.md
Create a .env.local file in the root directory and add the following:
MONGODB_URI=your_mongodb_connection_string
NEXTAUTH_SECRET=your_secret_key # if using authentication
NEXTAUTH_URL=http://localhost:3000
⚠️ Never commit.env.localto version control.
-
Clone the repository
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name -
Install dependencies
npm install # or yarn install -
Run the development server
npm run dev # or yarn dev -
Open in browser
http://localhost:3000
import mongoose from "mongoose";
const MONGODB_URI = process.env.MONGODB_URI;
if (!MONGODB_URI) {
throw new Error("Please define the MONGODB_URI environment variable");
}
let cached = global.mongoose;
if (!cached) {
cached = global.mongoose = { conn: null, promise: null };
}
async function connectDB() {
if (cached.conn) return cached.conn;
if (!cached.promise) {
cached.promise = mongoose.connect(MONGODB_URI).then((mongoose) => mongoose);
}
cached.conn = await cached.promise;
return cached.conn;
}
export default connectDB;Next.js API routes act as the backend:
/pages/api/*.js
Example:
GET /api/users
POST /api/users
-
Push your code to GitHub
-
Go to https://vercel.com
-
Import your GitHub repository
-
Add Environment Variables in Vercel Dashboard:
MONGODB_URI- Any other required secrets
-
Click Deploy
Vercel automatically builds and deploys your Next.js application.
npm run build
npm start- Server-side rendering (SSR)
- API routes with Node.js
- MongoDB integration
- Environment-based configuration
- Easy Vercel deployment
This project is licensed under the MIT License.
- Next.js Documentation
- MongoDB Atlas
- Vercel Platform
- Node.js Community