Skip to content

📋 Full stack app using PostgreSQL, Express, React & Node.js. Tutorial app

License

Notifications You must be signed in to change notification settings

AndrewJBateman/pern-stack-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ PERN Full Stack Database

  • PostgreSQL Express React Node (PERN) full-stack app, integrates React frontend with Node.js backend.
  • Currently shows weather data from OpenWeather API. Tutorial code (see 'Inspiration' below)
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

📄 Table of contents

📚 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
  • Postgresql shell commands: \l list all databases. \c database1 connect to database1. \dt inspect tables. \q to quit.

Frontend

  • React frontend includes a city selection user input field and a dropdown list of cities. Select a city to see the weather there.
  • JavaScript XML (JSX) used to write HTML elements in Javascript

📷 Screenshots

Backend screenshot Frontend screenshot

📶 Technologies - Backend

📶 Technologies - Frontend

💾 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 postgresql database & weather API access credentials to .env file
  • Run nodemon server for a dev server on port 5000

💾 Setup - Frontend

  • Change to /client directory
  • Install dependencies using npm i. (I have not tried this method and cannot be sure it will work)
  • Alternatively - and better - bootstrap a new React project using npx create-react-app my-app
  • Run npm start. Frontend will open at http://localhost:3000/

💾 Setup - Full stack

  • From top level \pern-stack-database run npm run dev for a dev server on port 5000 and a React fontend at http://localhost:3000/

💻 Code Examples - Backend

  // callback function - if error return it to callback. If no error then return rows (empty set)
  static insert (city, callback) {
    db.query('INSERT INTO cities (city_name) VALUES ($1)', [city], (err, res) => {
      if (err.error)
        return callback(err);
      callback(res);
    });
  }

💻 Code Examples - Frontend

  • method to add a city
// fetch an object that has a city property
  // after getting city list clear input field
  handleAddCity = () => {
    fetch('/api/cities', {
      method: 'post',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ city: this.state.newCityName })
    })
    .then(res => res.json())
    .then(res => {
      this.getCityList();
      this.setState({ newCityName: '' });
    });
  };

🆒 Features - Backend

  • All data stored in PostgreSQL database that can also be viewed and changed from the PostgreSQL shell (psql)

🆒 Features - Frontend

📋 Status & To-Do List

  • Status: Working front and back ends. App works and stores city names in PostgreSQL database. Deploy to Heroku not working - could be npm dependency issues or missing API access credentials in Heroku.
  • To-Do: Change backend so it checks if city already in database before adding it. Add commenting. Add functionality
  • Solve deploy issues: retry video 4 from 9.10 to create the correctly named database

👏 Inspiration/General Tools

📁 License

  • N/A

✉️ Contact

About

📋 Full stack app using PostgreSQL, Express, React & Node.js. Tutorial app

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published