React Node.js MySQL Full Stack Blog App Tutorial
If you are looking to build a full stack blog application using React, Node.js, and MySQL, you have come to the right place! In this tutorial, we will guide you through the process of creating a blog app with all the necessary functionalities.
Prerequisites
Before we begin, make sure you have the following installed:
- Node.js
- MySQL
- A code editor (e.g. Visual Studio Code)
Setting up the Backend
First, let’s set up the backend using Node.js and MySQL.
- Create a new directory for your project.
- Navigate to the project directory using the command line.
- Run the command
npm init
to initialize a new Node.js project. - Install the required dependencies by running
npm install express mysql
. - Create a new file called
server.js
and set up an Express server. - Connect to your MySQL database using the
mysql
module. - Create API endpoints for handling CRUD operations related to the blog posts.
- Test your API endpoints using a tool like
Postman
.
Building the Frontend
Now, let’s move on to building the frontend using React.
- Create a new directory inside your project directory called
client
. - Navigate to the
client
directory using the command line. - Run the command
npx create-react-app .
(the dot at the end is important) to create a new React app. - Delete the unnecessary files generated by
create-react-app
. - Install the required dependencies by running
npm install axios react-router-dom
. - Create components for displaying the list of blog posts, creating new blog posts, editing existing blog posts, and deleting blog posts.
- Fetch data from your backend API and update the state of your React components.
- Implement functionality for creating, editing, and deleting blog posts by making API requests.
- Style your app using CSS or a CSS framework like Bootstrap.
Putting it All Together
Now that you have the backend and frontend ready, it’s time to put everything together.
- Run your backend server using the command
node server.js
. - In a separate terminal, navigate to the
client
directory and run the commandnpm start
to start your React app. - Visit
http://localhost:3000
in your web browser to see your blog app in action!
Conclusion
Congratulations! You have successfully built a full stack blog app using React, Node.js, and MySQL. This tutorial should give you a good understanding of how to integrate these technologies together to create a functional and stylish blog application.
Remember, this is just a starting point. Feel free to customize and expand on the app to suit your specific needs. Happy coding!
Özel ders istiyorum?
can you create something like this, but with dashboard instead
Why the edit page after clicking on the pencil icon, goes to a blank page saying no route matched "/write?edit=2" . how to resolve this.
Why you always .. miss search bar. In a blog project . Include it for the next project
How come you can create cookies from node using CookieParser to a react client page? I have tried a thousand and one ways and it doesn't work.
Name of IDE used for SQL please
Hi! I cann't set cookie. Does anyone faced the same issue? The only difference I have with this project that I had to install CORS lib, the rest is the same
I don't know to much about MySQL! Should I watch this video?
Can I use mongodb instead of MySQL and host it on azure
1:43:00
not function!
How can I add a reset / change password option? For users
If your cookie doesnt appear @ 1h26m40s you have to set up CORS and credentials
in index.js import cors and use it like that:
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
When you call you API in login
await axios.post("http://localhost:8000/api/auth/login", inputs, {withCredentials: true})
Hello Sir thank you for your time and effort very good tutorial.
I have some issues with redirecting when i click on post1/ single page is not loading and i get an error Error: No route matches URL "/post/1"', error: Error
❤❤
error: {"code":"PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR","fatal":false}
for anyone stuck at "api call" (cors problem) OR "cookies",
1. you can "npm install cors" in your server folder
2. add this code to the server/index.js
import cors from "cors"; // or const cors = require('cors')
const app = express();
app.use(
// if use cors() only (empty), that means api can be called from any domain
cors({
origin: "http://localhost:3000", // this depend on your local client server, if client running in localhost:5173, just change it to 5173
credentials: true, // this for exchanging auth e.g. cookies
})
);
CMIIW i'm also learning
I didn't get the cookie in my Application tab, but I found it in my Network tab. Can someone explain this to me?
i can not create a cookie.
Great tutorial, Could you tell where can I deploy? Is it possible to host it on a shared hosting?