A modern React web application that displays New York Times Best Seller books using the NYT Books API. This application provides users with an intuitive interface to browse, search, and explore current and historical bestseller lists.
- Bestseller Lists: Browse current bestseller lists by category (Fiction, Non-Fiction, etc.)
- Top 5 Books: View the top 5 bestselling books across all categories
- Book Details: Detailed information about each book including cover, description, and purchase links
- Responsive Design: Modern, mobile-friendly interface built with Tailwind CSS
- Social Sharing: Share book recommendations on social media platforms
- Historical Data: Access to historical bestseller data
Want to get started quickly? Here's the fastest path:
# 1. Clone and setup
git clone https://github.com/yourusername/nyt-bestsellers.git
cd nyt-bestsellers/ClientApp
# 2. Install dependencies
npm install
# 3. Get NYT API key from https://developer.nytimes.com/
# 4. Create .env file with: REACT_APP_ApiKey=your_key_here
# 5. Start developing!
npm startThat's it! The app will open at http://localhost:3000. For detailed setup instructions, see Getting Started below.
- React 17.0.2 - Modern JavaScript library for building user interfaces
- React Router DOM 6.2.2 - Client-side routing for single-page application
- Tailwind CSS 3.0.23 - Utility-first CSS framework for rapid UI development
- React Icons 4.3.1 - Popular icon library for React applications
- React Share 4.4.0 - Social media sharing functionality
- React Toastify 8.2.0 - Toast notifications
- Moment.js 2.29.1 - Date manipulation and formatting
- Netlify Functions - Serverless functions for secure API proxy
- Node.js 18+ - Server runtime environment (native fetch support)
- NYT Books API v3 - Official New York Times Books API
- Secure Backend Proxy - API key secured in Netlify Functions, never exposed to client
- RESTful Architecture - Clean API service layer with centralized HTTP client
nyt-bestsellers/
βββ ClientApp/ # React frontend application
β βββ public/ # Static assets
β βββ src/
β β βββ components/ # React components
β β β βββ AboutUs.js
β β β βββ Banner.js
β β β βββ BestSellers.js
β β β βββ Book.js
β β β βββ Header.js
β β β βββ Home.js
β β β βββ Loading.js
β β β βββ Search.js
β β β βββ ...
β β βββ pages/ # Page components
β β β βββ Home.js
β β β βββ BestSellers.js
β β β βββ Book.js
β β β βββ ...
β β βββ http/ # API service layer
β β β βββ base.js # HTTP client configuration
β β β βββ service.js # API service methods
β β βββ common/ # Shared utilities
β β β βββ config.js # Application configuration
β β βββ context/ # React context providers
β β βββ svg/ # SVG assets
β βββ netlify/ # Netlify serverless functions
β β βββ functions/
β β β βββ api-proxy.js # Secure API proxy function
β β βββ README.md # Functions documentation
β βββ package.json
β βββ netlify.toml # Netlify configuration
β βββ tailwind.config.js # Tailwind CSS configuration
βββ RestAPIs/ # API documentation and testing
β βββ Books.http # HTTP request examples
βββ README.md
Before you begin, ensure you have the following installed on your system:
- Node.js (v14 or higher) - Download Node.js
- npm (comes with Node.js) or yarn package manager
- Git - Download Git
- NYT Books API Key (free) - Get one at NYT Developer Portal
# Clone the repository
git clone https://github.com/yourusername/nyt-bestsellers.git
# Navigate to the project directory
cd nyt-bestsellers- Visit the NYT Developer Portal
- Sign up for a free account (if you don't have one)
- Go to "Apps" and create a new app
- Select the "Books API" product
- Copy your API key (you'll need it in the next step)
Create a .env file in the ClientApp directory:
cd ClientApp
touch .env # On Windows: type nul > .envAdd your API key to the .env file:
REACT_APP_ApiKey=your_nyt_api_key_hereImportant:
- Never commit the
.envfile to version control (it's already in.gitignore)- This API key is only used for local development
- In production, the API key is secured in Netlify Functions and never exposed to clients
# Make sure you're in the ClientApp directory
cd ClientApp
# Install all project dependencies
npm installThis will install all required packages including React, Tailwind CSS, and other dependencies.
npm startThe application will:
- Open in your default browser at
http://localhost:3000 - Automatically reload when you make changes
- Show linting errors in the console
You should see the NYT Bestsellers homepage! π
- The app should load without errors
- You should see bestseller lists and books
- If you see errors, check the Troubleshooting section below
# Run tests in watch mode
npm test
# Run tests once
npm test -- --watchAll=false# Create an optimized production build
npm run build
# The build folder will contain the production-ready files-
Push your code to GitHub
git add . git commit -m "Initial commit" git push origin main
-
Connect to Netlify
- Go to Netlify
- Click "Add new site" β "Import an existing project"
- Connect to your GitHub repository
-
Configure Build Settings
- Base directory:
ClientApp - Build command:
npm run build - Publish directory:
ClientApp/build
- Base directory:
-
Add Environment Variable
- Go to Site settings β Environment variables
- Add new variable:
- Key:
NYT_API_KEY - Value: Your NYT API key
- Key:
-
Deploy!
- Click "Deploy site"
- Netlify will automatically build and deploy your app
# Install Netlify CLI globally
npm install -g netlify-cli
# Login to Netlify
netlify login
# Initialize and deploy
cd ClientApp
netlify init
netlify deploy --prodImportant: Make sure to set the NYT_API_KEY environment variable in Netlify:
- Go to your site settings β Environment variables
- Add
NYT_API_KEYwith your API key value
npm start- Runs the app in development modenpm test- Launches the test runnernpm run build- Builds the app for productionnpm run eject- Ejects from Create React App (one-way operation)
The application integrates with the following NYT Books API endpoints:
- List Names:
/names.json- Get available bestseller list names - Current Lists:
/current/{list-name}.json- Get current bestsellers by category - Overview:
/overview.json- Get top 5 books across all categories - Full Overview:
/full-overview.json- Get all books for all categories - History:
/best-sellers/history.json- Get bestseller history - By Date:
/{date}/{category}.json- Get books by specific date and category
- Modern Design: Clean, minimalist interface with custom color scheme
- Responsive Layout: Optimized for desktop, tablet, and mobile devices
- Loading States: Smooth loading indicators and skeleton screens
- Error Handling: User-friendly error messages and fallback states
- Accessibility: Built with accessibility best practices in mind
- Netlify Functions: The NYT API key is stored securely in Netlify environment variables and never exposed to the client
- Serverless Architecture: API key is handled server-side in Netlify Functions, never in client code
- No Client-Side Exposure: The API key is never included in URLs, network requests, or bundled JavaScript
- Environment Variables: API keys are stored in Netlify environment variables (never committed to git)
- HTTPS-only API communication in production
- CORS enabled for controlled cross-origin requests
- Input validation and sanitization
- No sensitive data in client-side code or network logs
- Serverless functions run in isolated environments
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
We love your input! We want to make contributing to NYT Bestsellers as easy and transparent as possible, whether it's:
- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features
- Becoming a maintainer
# Fork the repository on GitHub, then clone your fork
git clone https://github.com/yourusername/nyt-bestsellers.git
cd nyt-bestsellers
# Add the original repository as upstream
git remote add upstream https://github.com/originalowner/nyt-bestsellers.git# Create a new branch for your feature/fix
# Use a descriptive name that indicates what you're working on
git checkout -b feature/your-feature-name
# or for bug fixes:
git checkout -b fix/bug-descriptionBranch naming conventions:
feature/- New featuresfix/- Bug fixesdocs/- Documentation changesrefactor/- Code refactoringtest/- Adding or updating testsstyle/- Formatting, missing semicolons, etc.
- Write clean, readable code
- Follow the existing code style (see Code Standards below)
- Add comments for complex logic
- Update documentation if needed
- Add tests for new features
# Run tests to ensure nothing is broken
npm test
# Test the build
npm run build
# Make sure the app runs correctly
npm startWrite clear, meaningful commit messages:
git add .
git commit -m "Add feature: implement dark mode toggle"Commit message guidelines:
- Use present tense ("Add feature" not "Added feature")
- Use imperative mood ("Move cursor to..." not "Moves cursor to...")
- Limit the first line to 72 characters
- Reference issues and pull requests after the first line
- Example:
Fix: resolve API timeout issue The timeout was occurring due to missing error handling. Added try-catch block and timeout configuration. Fixes #123
# Fetch latest changes from upstream
git fetch upstream
# Rebase your branch on top of the latest main branch
git rebase upstream/main# Push to your fork
git push origin feature/your-feature-nameThen:
- Go to the original repository on GitHub
- You'll see a banner suggesting to create a Pull Request
- Click "Compare & pull request"
- Fill out the PR template (see below)
- Use functional components with hooks (no class components)
- Follow ES6+ syntax
- Use meaningful variable and function names
- Keep components small and focused (single responsibility)
- Extract reusable logic into custom hooks
- Use arrow functions for component definitions
Example:
// β
Good
const BookCard = ({ book, onSelect }) => {
const handleClick = () => {
onSelect(book);
};
return (
<div onClick={handleClick} className="book-card">
<h3>{book.title}</h3>
</div>
);
};
// β Avoid
const BookCard = ({book, onSelect}) => {
return <div onClick={() => onSelect(book)}><h3>{book.title}</h3></div>
}- Use Tailwind utility classes instead of custom CSS when possible
- Group related classes logically
- Use responsive prefixes (
sm:,md:,lg:) appropriately - Keep custom CSS in
index.cssminimal
- One component per file
- Use PascalCase for component file names:
BookCard.js - Use camelCase for utility files:
formatDate.js - Keep related files grouped in directories
// 1. React and third-party libraries
import React, { useState, useEffect } from 'react';
import { BrowserRouter } from 'react-router-dom';
// 2. Local components
import Header from '../components/Header';
import Loading from '../components/Loading';
// 3. Utilities and configs
import { formatDate } from '../common/utils';
import { API_BASE_URL } from '../common/config';
// 4. Styles (if needed)
import './Book.css';- Code follows the style guidelines
- Self-review completed
- Comments added for complex code
- Documentation updated (if needed)
- Tests pass locally
- No console errors or warnings
- Changes tested in multiple browsers (if UI changes)
When creating a Pull Request, include:
- Description: What does this PR do? Why?
- Type of Change:
- Bug fix
- New feature
- Breaking change
- Documentation update
- Testing: How was this tested?
- Screenshots (if UI changes): Before/after images
- Checklist: Confirm all items are checked
[Type] Brief description (e.g., "Fix: Resolve API timeout issue")
Types: Fix, Feature, Docs, Refactor, Test, Style
Found a bug? Have a feature request? Follow these guidelines:
- Check existing issues - Make sure the bug hasn't been reported
- Create a new issue with:
- Clear, descriptive title
- Steps to reproduce
- Expected vs. actual behavior
- Screenshots (if applicable)
- Environment info (OS, browser, Node version)
- Error messages or logs
- Check existing issues - See if the feature was already requested
- Create a new issue with:
- Clear description of the feature
- Why it would be useful
- Potential implementation ideas (optional)
- Any alternatives considered
- Open an issue for discussion
- Check existing issues and discussions
- Review the codebase and documentation
By participating in this project, you agree to maintain a respectful and inclusive environment for everyone. Be kind, constructive, and professional in all interactions.
Contributors will be recognized in:
- CONTRIBUTORS.md (coming soon)
- Release notes
- Project documentation
Thank you for contributing to NYT Bestsellers! π
Problem: App loads but no books are displayed, or you see API errors.
Solutions:
- Verify your API key is correct in
.envfile - Check that the
.envfile is in theClientAppdirectory (not root) - Ensure the API key variable is named exactly
REACT_APP_ApiKey - Restart the development server after adding/changing the
.envfile - Check the NYT Developer Portal to ensure your API key is active
Problem: Error: listen EADDRINUSE: address already in use :::3000
Solutions:
# Option 1: Kill the process using port 3000
# On Windows:
netstat -ano | findstr :3000
taskkill /PID <PID> /F
# On Mac/Linux:
lsof -ti:3000 | xargs kill -9
# Option 2: Use a different port
PORT=3001 npm startProblem: Module not found: Can't resolve '...'
Solutions:
# Delete node_modules and package-lock.json
rm -rf node_modules package-lock.json # Mac/Linux
rmdir /s node_modules && del package-lock.json # Windows
# Reinstall dependencies
npm installProblem: npm run build fails with errors
Solutions:
- Check for syntax errors in your code
- Ensure all imports are correct
- Verify environment variables are set
- Clear the build directory:
rm -rf buildthen rebuild - Check Node.js version:
node --version(should be v14+)
Problem: Tailwind utility classes not applying
Solutions:
- Ensure Tailwind is properly configured in
tailwind.config.js - Check that
index.cssimports Tailwind directives - Restart the development server
- Clear browser cache
Problem: CORS errors when making API requests
Solutions:
- In development, this shouldn't occur if using the
.envvariable - If using Netlify Functions, ensure they're properly configured
- Check that the API proxy function is correctly set up
Problem: Build fails on Netlify
Solutions:
- Verify build settings in Netlify dashboard
- Check that base directory is set to
ClientApp - Ensure
NYT_API_KEYenvironment variable is set - Review build logs for specific error messages
- Test build locally:
npm run build
If you're still experiencing issues:
- Search existing issues - Your problem might already be reported
- Check the logs - Browser console and terminal output
- Create a new issue with:
- Description of the problem
- Steps to reproduce
- Error messages
- Environment details (OS, Node version, browser)
- Screenshots (if applicable)
- NYT Books API Documentation: Developer Portal
- API Examples: Check
RestAPIs/Books.httpfor request examples - React Documentation: React Docs
- Tailwind CSS Docs: Tailwind CSS
- GitHub Issues: Open an issue for bugs, feature requests, or questions
- Discussions: Use GitHub Discussions for general questions and ideas
- Code Review: Submit a Pull Request for code review and feedback
When reporting issues, please include:
- What you're trying to do
- What you expected to happen
- What actually happened
- Steps to reproduce (if it's a bug)
- Environment information:
- Operating System
- Node.js version (
node --version) - npm version (
npm --version) - Browser and version (if relevant)
This information helps us understand and fix issues faster!
- v0.1.0 - Initial release with basic bestseller browsing functionality
- React 17.0.2 with modern hooks and functional components
- Tailwind CSS for styling
- NYT Books API v3 integration