React Calendar is an easy-to-use online calendar built with React Big Calendar. This full-stack demo showcases how to integrate a complex third-party UI library with the popular "MERN" development framework. The project includes key architectural elements like Mongoose, Redux, and JSON Web Token (JWT) to scale functionality easily. It utilizes public data from the Calendarific Holidays API.
React Calendar is a prime example of a MERN stack application, which consists of the following technologies:
- MongoDB: A document-based open-source database.
- Express: A web application framework for Node.js.
- React: A JavaScript front-end library for building user interfaces.
- Node.js: A JavaScript runtime environment that executes JavaScript code outside the browser.
The MERN stack allows for rapid development and ease of maintenance of full-stack web apps. To learn more, check out this YouTube tutorial.
src
├── config # Configuration files for the app
├── client # Frontend files
│ ├── assets # Static assets (e.g. images)
│ ├── components # Reusable React components
│ ├── pages # Page-level components
│ ├── store # Redux store and actions
│ ├── styles # CSS Modules for styling
│ ├── utils # Utility functions
│ ├── App.js # Main React entry point
│ ├── index.html # HTML template
│ ├── index.css # Global styles
│ ├── index.js # Entry point for React app
│ └── validation.js # Form validation utilities
├── server # Backend files
│ ├── controllers # Express.js controllers
│ ├── db # Database connection files
│ ├── middleware # Middleware for Express.js
│ ├── models # MongoDB database models
│ ├── routers # Express.js route definitions
│ ├── services # Services for data handling
│ └── utils # Backend utility functions
├── .babelrc # Babel.js configuration
├── .env.example # Sample environment variables file
├── .gitignore # Files to exclude from version control
├── .prettierrc # Prettier.js configuration
├── .jest.config.js # Jest.js configuration
├── .seedHolidayEvents.js # Script for seeding events to the DB
├── .webpack.development.js # Webpack configuration for dev mode
├── .webpack.production.js # Webpack configuration for prod mode
└── README.md # This file
React Calendar was built using Node.js v16. For the best compatibility, it's recommended to install a long-term support (LTS) version of Node.js.
- Download and Install Node.js: Node.js Official Website
- Verify Installation:
node -v
Create the following configuration files in the project root:
.env.development
.env.production
Refer to .env.example
for sample values. Add the following environment variables:
Variable | Description |
---|---|
PORT |
Port where the app will run |
MONGO_HOSTNAME |
Mongo host (e.g., localhost for dev) |
MONGO_PORT |
Mongo port (e.g., 27017) |
MONGO_DB |
Mongo database name |
API_URL |
Base API URL (e.g., http://localhost:3001/api ) |
CALENDARIFIC_KEY |
Calendarific API Key |
JWT_SECRET_KEY |
JWT Private Key |
JWT_EXPIRATION |
JWT expiration (seconds) |
JWT_REFRESH_EXPIRATION |
JWT refresh expiration (seconds) |
React Calendar works best with MongoDB v4.4.6, though external instances are supported.
- Install MongoDB: Download MongoDB
- Start MongoDB:
mongod
- Create Database:
mongo use reactcalendar_db db.app.insert({ _id: 1, message: "first doc" })
Verify your database using tools like DbGate or Robo 3T.
Seed default calendar events:
node seedHolidayEvents.js
Expected Output:
Connected correctly to server
Database seeded!
Verify data in the events
collection.
- Build Production Assets:
npm run build
- Start the App:
npm run start
To run with PM2:
npm install pm2 -g
npm run pm2
npm run dev
Expected Output: Server started at http://localhost:3001
Access the frontend at http://localhost:8080.
React Calendar uses JWT for authentication.
- Faster database interactions
- Better scalability
- Portability across services
Environment Variable:
JWT_SECRET_KEY
: Used as the private key for JWT.
Each user document contains roles (user
, moderator
, or admin
). These can be used to implement authorization if needed.
The frontend is a Single-Page Application (SPA) using React and Redux:
- Routing: Client-side routing via
React Router
- Data Storage: Persistent state with Redux and
localStorage
If the app appears out of sync, clear localStorage.state
and reload.
Components use CSS Modules for styling:
- Modular and reusable styles
- Locally-scoped class names
- Ensure
.env.production
contains all environment variables before building. - To disable Hot Module Reloading (HMR) in development, remove
hot: true
fromwebpack.development.js
.
💻 Happy Coding! 🎉