app.use('/api/login', AuthRouter)
accept POST request, handles user secure login, expects username and password, sends back encrytped credentials that is then stored in local storage in browser
app.use('/api/users', UsersRouter)
accepts POST request, handles user registration, expects username and password, sends back encrytped credentials that is then stored in local storage in browser
app.use('/api/businesses', BusinessesRouter)
accepts GET request, handles fetching restaurants from Yelp API, expects browser's latitude and longitude that is used to fetch the restaurants in your location
app.use('/api/users_businesses', UsersBusinessesRouter)
accepts GET, POST, DELETE requests, handles the relation between users and saved restaurants under their account, expects encrytped user id
-
install psql -- PostgreSQL interactive terminal https://www.postgresql.org/download/
-
open terminal and run
pg_ctl start
-
run
psql
to run psql shell -
create user
CREATE USER [your-username] WITH option [option-you-want];
-- make sure to use an option that allows to create a database (for more info see the docs https://www.postgresql.org/docs/current/sql-createuser.html) -
create database
CREATE DATABASE where_to_eat_db WITH OWNER [your-username];
(for more info see the docs https://www.postgresql.org/docs/current/sql-createdatabase.html) -
move to where_to_eat_db database
\c where_to_eat_db
-
create tables
CREATE TABLE users ( id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, user_name TEXT NOT NULL, user_password TEXT NOT NULL);
CREATE TABLE business ( id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, business_id TEXT NOT NULL);
CREATE TABLE user_businesses ( user_id INTEGER REFERENCES users(id) NOT NULL, business_id INTEGER REFERENCES business(id) NOT NULL, PRIMARY KEY (user_id, business_id));
-
OPTIONAL: seed the table
users
with demo credentialsINSERT INTO users (user_name, user_password)
VALUES
('demo_user', '$2a$04$HNAwLgr8vBhbKfbHUKRane/eBWJ5WLzT12WmANApEAex7W.d91jhG');
Note: the password for demo_user is already hashed, you can login with user namedemo_user
and passworddemo_password
-
cd
into the desired directory -
clone this repository
git clone https://github.com/alexandrakollarova/where-to-eat-api
-
cd
into the cloned repository -
install node dependencies
npm install
-
open config.js file and comment out the remote database deployed on Heroku and uncomment
DATABASE_URL: process.env.DATABASE_URL || 'postgresql://postgres@localhost/where_to_eat_db'
to use the database you created and run on your local machine -
start the server
npm start
or start use nodemon for the appnpm run dev
-
run tests
npm test