Welcome to the Hack4Impact Bootcamp! In this session, you will be working on a "Live Pulse Poll" application. This is a simple full-stack Next.js application where users can vote for their favorite food, and results are updated in real-time.
Before getting started, ensure you have Node.js installed on your machine.
- Download the LTS (Long Term Support) version from the official Node.js website.
- Run the installer and follow the prompts.
- Restart your terminal (Command Prompt or PowerShell).
- Verify installation by running:
node -vandnpm -v.
Option 1: Using the Installer
- Download the LTS package from nodejs.org.
- Run the installer.
Option 2: Using Homebrew (Recommended)
- Open Terminal.
- If you don't have Homebrew, install it from brew.sh.
- Run:
brew install node - Verify:
node -vandnpm -v.
- Open your terminal.
- Update your package list:
sudo apt update - Install Node.js and npm:
sudo apt install nodejs npm - Verify:
node -vandnpm -v.
-
Navigate to the project directory:
cd h4i-bootcamp -
Install dependencies:
npm install
-
Run the development server:
npm run dev
-
Open the app: Visit http://localhost:3000 in your browser.
Search for TODO comments in the codebase to find where you need to write code.
- File:
app/page.tsx - Goal: Improve the user experience when a vote is cast.
- Action: When a user clicks a button, disable the buttons or show a loading state so they know something is happening.
- File:
app/page.tsx - Goal: Send the user's choice to the server.
- Action: Implement the
fetch()call insidehandleVote. It needs to send aPOSTrequest to/api/votewith the selected option in the body.
- File:
app/api/vote/route.ts - Goal: Actually count the votes!
- Action: In the
POSTfunction, write the logic to increment the vote count in thevotesobject for the received option.
- File:
app/page.tsx - Goal: See other people's votes without refreshing the page.
- Action: Use the
useEffecthook andsetIntervalto "poll" the server (fetch data repeatedly) every 5 seconds to update the results. - Concept: This demonstrates "Polling" vs "Push" (WebSockets).