React Express Sequelize
React Express Sequelize
It allows you to
create reusable UI components and efficiently update the UI when the underlying
data changes.
npm init -y
Create a new file called server.js and add the following code:
app.use(express.json());
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Open the src/App.js file and replace the existing code with the following:
import React, { useEffect, useState } from 'react';
function App() {
const [users, setUsers] = useState([]);
useEffect(() => {
fetch('/api/users')
.then((response) => response.json())
.then((data) => setUsers(data));
}, []);
return (
<div>
<h1>User List</h1>
<ul>
{users.map((user) => (
<li key={user.id}>
{user.name} - {user.email}
</li>
))}
</ul>
</div>
);
}
Open the server.js file and add the following code to define a route for fetching
users:
React:
Express.js:
MDN Web Docs - Express.js: MDN Web Docs provide detailed documentation on
Express.js, including guides, tutorials, and examples. Visit:
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs
Sequelize:
Sequelize Crash Course by Traversy Media: Traversy Media offers a crash course on
Sequelize on YouTube. It provides a quick introduction to Sequelize and
demonstrates its usage with a PostgreSQL database. Visit:
https://www.youtube.com/watch?v=pxpZo16km6U
Sequelize - The Node.js ORM for PostgreSQL, MySQL, SQLite, and MSSQL: This tutorial
by Scotch.io provides a step-by-step guide on using Sequelize with different
databases. It covers model creation, associations, and querying. Visit:
https://scotch.io/tutorials/getting-started-with-node-express-and-postgres-using-
sequelize