https://github.com/todd-demone/lighthouse-bnb
The primary purpose of this project was to design a relatIonal database and use SQL and PostgreSQL to create and query the database. The SQL was incorporated into the Node.js/Express backend.
https://github.com/todd-demone/lighthouse-bnb
database-design javascript postgresql sql
Last synced: about 1 month ago
JSON representation
The primary purpose of this project was to design a relatIonal database and use SQL and PostgreSQL to create and query the database. The SQL was incorporated into the Node.js/Express backend.
- Host: GitHub
- URL: https://github.com/todd-demone/lighthouse-bnb
- Owner: todd-demone
- Created: 2022-01-19T19:33:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-04T21:05:28.000Z (over 4 years ago)
- Last Synced: 2025-09-23T16:41:12.542Z (9 months ago)
- Topics: database-design, javascript, postgresql, sql
- Language: JavaScript
- Homepage:
- Size: 2.56 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lighthouse BnB
This pre-existing Airbnb clone used in-memory objects to store its data, so I incorporated a database into the backend of this application (more details below).
## Purpose
I worked on Lighthouse BnB while completing the [Lighthouse Labs Web Development Flex Program](https://www.lighthouselabs.ca/en/web-development-flex-program).
The primary objectives of this project were:
- design a relational database using [database design](https://en.wikipedia.org/wiki/Database_design) best practices, including applying the [normalization rules](https://en.wikipedia.org/wiki/Database_normalization)
- use SQL and PostgreSQL to create the database and tables and seed the tables
- create a connection to the database use `pg` and `dotenv`
- create database queries
* functions for user-related queries:
* `getUserWithEmail`
* `getUserWithId`
* `addUser`
* functions for api-related queries:
* `getAllProperties` (including filters for property search)
* `getAllReservations`
* `addProperty`
- call the db query functions from within the route handler functions and utilize the returned data as needed.
## Dependencies
The instructions below assume that the following software is installed on your computer:
- [git](https://git-scm.com/)
- [Node.js](https://nodejs.org) (I used v. 12.8.2)
- [npm](https://www.npmjs.com/) - included with Node.js
- [PostgreSQL](https://www.postgresql.org/)
## Instructions for running the app
1. Clone the repository and install the dependencies via npm:
```bash
git clone git@github.com:todd-demone/lighthouse-bnb.git
cd lighthouse-bnb
npm install
```
2. Create a `.env` file in your root folder to store your database-related environment variables. An example file `.env.example` has been included in the root folder of the app.
3. Before proceeding, you may need to set up a password for your user on psql (the PostgreSQL command-line tool):
- Open `psql` on the command line
- Type `\password`
- Type your new password, hit Enter, type the password again, hit Enter.
4. Create and seed the database:
- Open `psql` on the command line
- create a database
- connect to the database
- create the tables
- seed the tables with some fake data
```
CREATE DATABASE lightbnb;
\c lightbnb;
\i db/migrations/01_schema.sql;
\i db/seeds/01_seeds.sql;
\i db/seeds/02_seeds.sql;
```
5. Run the server.
```
npm run start
```
6. go to in your browser.
7. Click the login link. Use the following sample user data to complete the login:
- email: `jacksonrose@hotmail.com`
- password: `password`
## Npm Dependencies
- [bcrypt](https://www.npmjs.com/package/bcrypt)
- [cookie-session](https://www.npmjs.com/package/cookie-session)
- [dotenv](https://www.npmjs.com/package/dotenv)
- [express](https://expressjs.com/)
- [nodemon](https://www.npmjs.com/package/nodemon)
- [pg](https://node-postgres.com/)
- [sass](https://sass-lang.com/)
## Author
[Todd Demone](https://github.com/todd-demone)
## Project Structure
```
├── db
│ ├── migrations
│ │ ├── 01_schema.sql
│ ├── queries
│ │ ├── 01_single_user.sql
│ │ ├── 02_avg_length_of_reservation.sql
│ │ ├── 03_property_listings_by_city.sql
│ │ ├── 04_most_visited_cities.sql
│ │ ├── 05_all_my_reservations.sql
│ ├── seeds
│ │ ├── 01_seeds.sql
│ │ ├── 02_seeds.sql
├── public
│ ├── index.html
│ ├── javascript
│ │ ├── components
│ │ │ ├── header.js
│ │ │ ├── login_form.js
│ │ │ ├── new_property_form.js
│ │ │ ├── property_listing.js
│ │ │ ├── property_listings.js
│ │ │ ├── search_form.js
│ │ │ └── signup_form.js
│ │ ├── index.js
│ │ ├── libraries
│ │ ├── network.js
│ │ └── views_manager.js
│ └── styles
├── sass
└── server
├── database
│ └── apis.js
│ └── connection.js
│ └── users.js
├── routes
│ ├── apiRoutes.js
│ └── userRoutes.js
└── express_server.js
```