Skip to content

nglong05/CRUDForum-using-Node.js-Express-React-MySQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project is a simple forum web application where users can register, log in, create, edit, and view posts. It includes different roles for users, such as regular users and admins, with different levels of access and functionalities. Admins can approve users, grant admin rights, and manage posts and user data, while regular users can create and manage their own posts.

Technologies Used

  • Backend:

    • Node.js (Express.js)

    • MySQL for database management

  • Frontend:

    • React for building the user interface

    • Bootstrap for styling

  • Authentication:

    • JSON Web Tokens (JWT) for securing routes and user authentication
  • Deployment:

    • ngrok for tunneling the backend to be publicly accessible during development

Features

User Features

  • User Registration: Users can create a new account by providing a username, email, and password.

  • User Login: After registration, users can log in using their credentials.

  • Create Posts: Users can create new posts, including a title, body, and optional file link.

  • Edit Posts: Users can edit the posts they have created.

  • View Posts: Users can view posts created by other users.

  • Search Posts: Users can search for posts by title or body content.

Admin Features

  • User Management: Admins can approve new users, grant them admin rights, and manage their roles.

  • Export User Data: Admins can export user data to a CSV file.

  • Post Management: Admins can edit or delete any posts in the system.

Database Structure

The MySQL database consists of two main tables:

  • users: Stores user information including username, email, password (hashed using bcrypt), and role (user or admin).

  • posts: Stores posts, including the title, body, and associated user email. It also has a field indicating whether the post was created by an admin.

Installation

Prerequisites

Node.js (version 14 or later)

MySQL (version 8 or later)

ngrok (optional, for tunneling)

Backend Setup

Clone the repository:
git clone <repository-url>
cd <repository-directory>

Navigate to the backend directory and install dependencies:

cd backend
npm install

Set up the database:

  • Make sure you have MySQL running.

  • Import the init.sql script to create the necessary database and tables:

mysql -u <your-username> -p < init.sql

Run the server:

node src/app.js
cd frontend
npm install
REACT_APP_HOST=http://localhost:5000
npm start

File Structure

.
├── backend/                   # Backend application (Node.js, Express, MySQL)
│   ├── src/
│   │   ├── app.js             # Main entry point for the backend
│   ├── init.sql               # SQL script for setting up the database
│   └── ...
├── frontend/                   # Frontend application (React)
│   ├── public/                
│   ├── src/
│   │   ├── pages/             # All page components
│   │   ├── App.js             # Main entry point for React application
│   │   └── ...
├── start.sh                   # Script to start both backend and frontend
└── ...

Environment Variables

REACT_APP_HOST: The URL of the backend API.

Authentication

The application uses JWT (JSON Web Token) for handling authentication. On login, the backend generates a token that the frontend stores in the browser's localStorage. This token is then used to authenticate the user on subsequent requests.

About

A simple forum web application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published