pern-stack-auth
pern-stack-auth copied to clipboard
:clipboard: Repair. PERN stack todo app with jwt user authentication
:zap: PERN Full Stack Todo
- PostgreSQL Express React Node (PERN) full-stack app, integrates React frontend with Node.js backend. Tutorial code from The Stoic Programmers (see 'Inspiration' below)
- Note: to open web links in a new window use: ctrl+click on link
:page_facing_up: Table of contents
-
:zap: PERN Stack Auth
- :page_facing_up: Table of contents
- :books: General info
- :camera: Screenshots
- :signal_strength: Technologies
- :floppy_disk: Setup
- :wrench: Testing
- :computer: Code Examples
- :cool: Features
- :clipboard: Status, Testing & To-Do List
- :clap: Inspiration
- :file_folder: License
- :envelope: Contact
:books: General info
Backend
- PostgreSQL needs to be installed and running - I started it from my Windows 10 PostgreSQL 12 dropdown option 'SQL shell (psql)'
- Postman used to test the backend before frontend was available
Frontend
- React frontend includes a simple todo list with a user input field and a table of todos below. User can edit and delete todos.
- JavaScript XML (JSX) used to write HTML elements in Javascript
- React Fragments used to show table of todos as a row with columns in the DOM
:camera: Screenshots
:signal_strength: Technologies - Backend
- PostgreSQL v14
- PostgreSQL Installer for Windows
- Express.js middleware v4
- Node.js v16
- Nodemon v2 npm module so backend server will automatically restart after code changes
- Postman API to simulate a frontend
:signal_strength: Technologies - Frontend
- React framework v16
- Bootstrap v4 component library
:floppy_disk: Setup - Backend
- Change to
/server
directory - Install dependencies using
npm i
- Install nodemon globally if you don't already have it
- Install PostgreSQL & run it (requires the password you created during installation)
- Add database access credentials to
db.js
- recommend installing npm dotenv & using .env to hide credentials if commiting to Github - Postgresql shell commands:
\l
list all databases.\c
database1 connect to database1.\dt
inspect tables.\d+
inspect table & show relation information.\q
to quit. - Run
nodemon server
for a dev server -
http://localhost:5000/
can be accessed for CRUD operations such as POST, GET, PUT, DELETE etc. using Postman
:floppy_disk: Setup - Frontend
- Change to
/client
directory - Install dependencies using
npm i
. - run
npm start
. Frontend will open athttp://localhost:3000/
:computer: Code Examples - Backend
- backend
index.js
: express post method used to add new todo [description] to postgreSQL database using SQL INSERT INTO statement
// create a todo
app.post('/todos', async (req, res) => {
try {
const { description } = req.body;
const newTodo = await pool.query(
"INSERT INTO todo (description) VALUES($1) RETURNING *",
[description]
);
res.json(newTodo.rows[0]);
} catch (err) {
console.error(err.message);
}
})
:computer: Code Examples - Frontend
- function that runs when user presses 'Add' button: the input body (description) is converted from a JavaScript object to a JSON string & POSTed to the todo database
const onSubmitForm = async e => {
e.preventDefault();
try {
const body = { description };
const response = await fetch("http://localhost:5000/todos", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body)
});
console.log("Successfully added todo: ", response);
window.location = "/";
} catch (err) {
console.error(err.message);
}
};
:cool: Features - Backend
- All data stored in PostgreSQL database that can also be viewed and changed from the PostgreSQL shell (psql)
:cool: Features - Frontend
- React app created from the command prompt using Create React App
- Uses the Bootstrap basic table to list todos
- Bootstrap 4 Modal dialog box
:clipboard: Status & To-Do List
- Status: Error in registration
- To-Do: Fix errors and complete testing
:clap: :wrench: Inspiration/General Tools
- PERN Stack Course - PostgreSQL, Express, React and Node
- Youtube video: Learn Database Design by combining our JWT and PERN stack Todo List app together Part 1
- Youtube video: Learn Database Design by combining our JWT and PERN stack Todo List app together, part 2
- Youtube video: How to Deploy a PERN application on Heroku
- React documentation
- Enable Emmet support for JSX in Visual Studio Code | React
- js-beautify for VS Code
:file_folder: License
- N/A
:envelope: Contact
- Repo created by ABateman, email: [email protected]