Name | Description |
---|---|
.env | Used for enviroment variables |
.gitignore | Specifies intentionally untracked files to ignore |
LICENSE | License of the project |
README.md | Future documentation of repository |
README.pdf | University documentation |
ΥΠΟΧΡΕΩΤΙΚΗ_ΕΡΓΑΣΙΑ_2020.pdf | Objective and specifications of project |
dev-notes.md | Developer notes |
Procfile | Heroku apps include a Procfile that specifies the commands that are executed by the app on startup. |
package.json | Central repository of configuration for tools |
package-lock.json | Stores an exact, versioned dependency tree |
app.js | Starting point of application |
controllers/ | Folder containing various controllers |
database/ | Folder containing various database files |
middleware/ | Folder containing the middleware used in the application |
models/ | Folder containing schemas of database |
routes/ | Folder containing the routes of the application |
views/ | Folder containing the Front end part of the application |
How to Deploy Multiple Apps Under a Single GitHub Repository to Heroku
git clone https://github.com/constantinosgeorgiou/breezebnb.git
cd breezebnb
npm init
node app.js
# NOTE: create .env file
touch .env
# Put enviroment variables in .env file
npm install
heroku local web
Name | Description |
---|---|
Express | Web application framework |
node-postgres | Used for interfacing with the PostgreSQL database |
dotenv | Loads environment variables from a .env file into process.env |
- | - |
- | - |
NOTE: In the documentation hyperlink the name of each dependency to its corresponding website
Best practices for REST API design
Best Practices for Node.js Development
Prerequisites:
- heroku --version
- node --version
- npm --version
- git --version
How to install and use PostgresQL
sudo apt-get install postgresql
How to setup a free PostgreSQL database on Heroku
Setting up a RESTful API with Node.js and PostgreSQL
Log into the Heroku PostgreSQL instance:
heroku pg:psql postgresql-transparent-00915 --app breezebnb
Create your table and entries on Heroku Postgres:
cat <sql file OR model> | heroku pg:psql postgresql-transparent-00915 --app breezebnb
# Example for heroku:
cat models/listings.sql | heroku pg:psql postgresql-transparent-00915 --app breezebnb
Create your table and entries on local Postgres:
cat <sql file OR model> | psql -d <database name> -U <user name>
# OR
cat database/config.sql | psql -d <database name> -U <user name>
cat models/* | psql -d <database name> -U <user name>
# Examples for local dabatase:
# For all models:
cat models/* | psql -d breezebnb -U breezebnb
# For single files:
cat model/users.sql | psql -d breezebnb -U breezebnb
cat model/listings.sql | psql -d breezebnb -U breezebnb
Seed database:
# LOCAL -> Generate seed and seed database:
# --------------------------------------
node database/generate-seed.js > database/seed.sql && cat database/seed.sql | psql -d <database> -U <user>
# Example
node database/generate-seed.js > database/seed.sql && cat database/seed.sql | psql -d breezebnb -U breezebnb
# HEROKU -> Generate seed and seed database:
# --------------------------------------
node database/generate-seed.js > database/seed.sql && cat database/seed.sql | heroku pg:psql postgresql-transparent-00915 --app breezebnb
# Generate seed only
# ------------------
node database/generate-seed.js > database/seed.sql
# Seed database only
# ------------------
cat database/seed.sql | psql -d <database> -U <user>
Test and deploy:
heroku local web
Postgres service commands:
Command | Action |
---|---|
service postgresql status |
Status check |
service postgresql start |
Start Postgres |
service postgresql stop |
Stop Postgres |
service postgresql restart |
Restart Postgres |
Log in to postgres superuser:
psql -U postgres
FIX: "psql: FATAL: Peer authentication failed for user"
Log in to breezebnb:
psql -d postgres -U breezebnb
FIX: "Peer authentication failed for user "breezebnb" => in pg_hba.conf change local all all peer
from peer
to md5
, then restart the service service postgresql restart
Display information regarding current connection to postgres:
\conninfo
Connect to database:
\c <database>
\c breezebnb
\du
\l
\dt
\dT
\dx
Show table data:
TABLE tablename;
Rotate Heroku database credentials:
heroku pg:credentials:rotate <database-name> --app <app-name>
# Example
heroku pg:credentials:rotate postgresql-color-99999 --app breezebnb
Reset Heroku database:
heroku pg:reset --app breezebnb
Information for Heroku database:
heroku pg:info
- Download OmniDB for linux
- Setup
- Connections->New Connection
- Fill in data
- Save Data
- Press green tick button in Action field
- Enter password
- Explore path and find our database PostgreSQL 12.3->Database->(database_name)->Schemas (If password asked enter it again)
- Now you can view and edit database tables
-
users
-
Phone numbers are stored as VARCHAR
-
what is the right data type for unique key in postgresql DB?
-
JavaScript Naming Convention Best Practices
45 Useful JavaScript Tips, Tricks and Best Practices
Jake Archibald: In The Loop - JSConf.Asia watch in order to understand the inner workings of JS
React Tutorial: An Overview and Walkthrough
How to consume a RESTful API in React
npm install @material-ui/lab
npm i --save react-bootstrap
npm install helmet --save
npm i -S bootstrap
npm i -S popper.js
npm i -S jquery
npm install axios --save
npm install cloudinary --save
Define the following enviroment variables for the application to run properly
# Port that server is listening
PORT = <port>
# Cors allows only requests from this url
CORS_ORIGIN = "http://localhost:<port>/"
# Database credentials
DATABASE_URI = 'postgresql://<username>:<password>@<host>:<port>/<database>'
# JWT secret
JWT_SECRET = "<256 bit alphanumeric string>"