Skip to content

Latest commit

 

History

History
328 lines (226 loc) · 9.65 KB

dev-notes.md

File metadata and controls

328 lines (226 loc) · 9.65 KB

Developer notes

File structure:

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

Build and run server

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

Build and run app locally:

npm install
heroku local web

Dependencies

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

NodeJS on Heroku

Best practices for REST API design

Getting started with NodeJS

Deploying NodeJS

Best Practices for Node.js Development

Prerequisites:

  • heroku --version
  • node --version
  • npm --version
  • git --version

Preparing a Codebase for Heroku Deployment

Guide

PostgresQL

How to install and use PostgresQL

sudo apt-get install postgresql

Installation & Setup

Some postgres best practices

How to setup a free PostgreSQL database on Heroku

Setting up a RESTful API with Node.js and PostgreSQL

Shell commands

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

List users:

\du

List databases:

\l

Show tables:

\dt

Show types

\dT

Show extensions

\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

PostgresQL GUI OmniDB

  1. Download OmniDB for linux
  2. Setup
  3. Connections->New Connection
  4. Fill in data
  5. Save Data
  6. Press green tick button in Action field
  7. Enter password
  8. Explore path and find our database PostgreSQL 12.3->Database->(database_name)->Schemas (If password asked enter it again)
  9. Now you can view and edit database tables

Postgres database design:

Tables:

Javascript

JavaScript Best Practices

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

React Tutorial: An Overview and Walkthrough

Intro to React

How to consume a RESTful API in React

Modules Installation Commands

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

.env

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>"