A simple Random Quote Generator app built with Node.js for the backend and Next.js for the frontend. The app allows users to view random quotes and add their own quotes to the database.
- Backend (Node.js + Express):
- ✅ Fetches a random quote.
- ✅ Allows users to add new quotes.
- Frontend (Next.js):
- ✅ Displays quotes fetched from the backend.
- ✅ Allows users to interact with the system and view new random quotes.
- Backend:
- Node.js
- Express.js
- CORS (Cross-Origin Resource Sharing)
- Body-parser
- Frontend:
- Next.js
- Axios (for making HTTP requests)
- Database (Optional):
- MongoDB / SQLite (can be used to store quotes persistently)
Follow the steps below to get the application up and running on your local machine.
Step 1: Setup Node.js & Express Backend We'll create an API that:
- ✅ Returns a random quote.
- ✅ Allows users to add new quotes.
Run the following commands:
mkdir quote-generator
cd quote-generator
npm init -y
npm install express cors body-parser
✅ Run the Backend:
node server.js
Let's build a simple Next.js app to fetch and display quotes.
Run:
npx create-next-app@latest quote-app
cd quote-app
npm install axios
Edit the file pages/index.js
npm run dev
To ensure compatibility with the latest Next.js, use Node.js version 20.x or higher:
nvm install 20
node -v
- Backend should be running on
http://localhost:5000
- Frontend should be running on
http://localhost:3000
Visit http://localhost:3000 and you should see a random quote displayed with a button to fetch a new one.