Skip to content

Commit 227b6c2

Browse files
committed
Minor updates
1 parent ceb7cbc commit 227b6c2

File tree

29 files changed

+163
-142
lines changed

29 files changed

+163
-142
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/public/** linguist-vendored
2+
**/Styles/** linguist-vendored

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/build
1111
*/coverage
1212
client/src/Assets/Styles/**/*.css
13-
!client/src/Assets/Styles/Layouts/Bootstrap.css
1413
!client/src/Assets/Styles/Style.css
1514

1615
# misc

README.md

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
# Node API and Client Boilerplate
22
Required node version is `9.2.1`. The [API](https://github.com/rickyhurtado/node-client-and-api-boilerplate/tree/master/api) app is powered by [Express](https://expressjs.com/) and [PostgreSQL](https://www.postgresql.org/) database and the [client](https://github.com/rickyhurtado/node-client-and-api-boilerplate/tree/master/client) app is bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app) and [Bootstrap 3.3](http://getbootstrap.com/docs/3.3/) framework and theme.
33

4-
## Running the Apps
4+
## Starting the Apps
55

6-
### Cloning the project:
6+
### Express API
77

8-
Open a terminal console and run the following scripts:
9-
10-
```
11-
git clone [email protected]:rickyhurtado/node-client-and-api-boilerplate.git
12-
cd node-client-and-api-boilerplate
13-
```
14-
15-
### Starting the apps in local:
16-
17-
**Express API**
8+
Note: Only change the environment variables for `POSTGRES_USER` and `POSTGRES_PASSWORD` if working on local machine.
189

1910
Open a terminal console and change the project directory from `root` to `api`. Copy `.env.dist` to `.env` and change the values of the environment variables if needed.
2011

@@ -28,130 +19,122 @@ POSTGRES_USER=express_api_user
2819
POSTGRES_PASSWORD=root
2920
```
3021

31-
Note: Only change the environment variables for `POSTGRES_USER` and `POSTGRES_PASSWORD` if working on local machine.
32-
33-
Then run the following scripts in the terminal:
22+
Then run the following commands:
3423

3524
```
3625
yarn
3726
yarn start
3827
```
3928

40-
Access the client app at <http://localhost:7770>.
29+
Note: The database must be created and initialized after starting the app on fresh installation. See **Database using PostgreSQL and Sequelize** section. See **Bash Commands** section for Docker.
30+
31+
Access the app at <http://localhost:7770>.
4132

42-
**React App**
33+
### React App
4334

4435
Open a terminal console and change the project directory from `root` to `client`. Copy `.env.dist` to `.env` and change the values of the environment variables if needed.
4536

4637
```
38+
REACT_APP_SITE_NAME=React App Boilerplate
4739
REACT_APP_API_BASE_URL=http://localhost:7770
4840
REACT_APP_API_SIGN_IN_URL=http://localhost:7770/sign-in
4941
REACT_APP_API_SIGN_OUT_URL=http://localhost:7770/sign-out
5042
REACT_APP_API_VERIFY_TOKEN_URL=http://localhost:7770/verify-token
5143
REACT_APP_API_JWT_SECRET=jwtsecretcode
5244
```
5345

54-
Then run the following scripts in the terminal:
46+
Then run the following commands:
5547

5648
```
5749
yarn
5850
yarn start
5951
```
6052

61-
To generate the `./client/src/Assets/Styles/Style.css`, open another terminal window and change the project directory from `root` to `client` then run the following script:
53+
Note: See **Bash Commands** section for Docker.
54+
55+
To generate the `./client/src/Assets/Styles/Style.css`, open another terminal console and change the project directory from `root` to `client` then run the following command:
6256

6357
```
6458
yarn run watch-css
6559
```
6660

67-
The script above works only in Mac with the `fsevents` module installed. Run the script below as an alternative:
61+
The command above works only in Mac with the `fsevents` module installed. Run the command below as an alternative:
6862

6963
```
7064
yarn run build-css
7165
```
7266

73-
Note: You must run the script above manually everytime you made changes to `.scss` files. All the `*.scss` files shall be compiled to `*.css` but only the `Style.css` is included in the repository.
67+
Note: You must run the command above manually everytime you made changes to `.scss` files. All the `*.scss` files shall be compiled to `*.css` but only the `Style.css` is included in the repository.
7468

75-
Access the API app at <http://localhost:7771>.
69+
Access the client app at <http://localhost:7771>.
7670

77-
### Starting the React App and Express API in Docker:
71+
## Docker
7872

79-
Download and install the [Docker Community Edition](https://www.docker.com/community-edition). With [Docker](https://www.docker.com/), both the API and client apps can be started using one script. First, do the same instructions above except for the `yarn`, `yarn start`, and `yarn global add detect-port` scripts. Then change directory to `root`, and run the following scripts in the terminal:
73+
Download and install the [Docker Community Edition](https://www.docker.com/community-edition). With [Docker](https://www.docker.com/), both the API and client apps can be started using one command.
8074

81-
```
82-
docker-compose build
83-
docker-compose up
84-
```
85-
86-
Note: The `docker-compose build` script is executed only once if the Docker image has not been created yet.
87-
88-
To shutdown the apps, press `CTRL+C` and run the following script in the terminal:
89-
90-
```
91-
docker-compose down
92-
```
75+
Note: See **Bash Commands** section for Docker.
9376

94-
The `yarn run watch-css` script should be running on a separate terminal window for client app.
77+
The `yarn run watch-css` command should be running on a separate terminal console for client app.
9578

9679
## Database using PostgreSQL and Sequelize
9780

98-
### Local
99-
10081
**Installing PostgreSQL**
10182

10283
**Mac:** [Getting Started with PostgreSQL on Mac OSX](https://www.codementor.io/engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb)
10384
<br>
10485
**Windows:** [Installing PostgreSQL, Creating a User, and Creating a Database](https://confluence.atlassian.com/display/CONF30/Database+Setup+for+PostgreSQL+on+Windows)
10586

106-
NOTE: For Mac users, you can run the PostgreSQL server on a separate terminal console by running the following script:
87+
NOTE: For Mac users, you can run the PostgreSQL server on a separate terminal console by running the following command:
10788

10889
```
10990
postgres -D /usr/local/var/postgres
11091
```
11192

112-
**Database Create and Drop Commands**
93+
**Create and Initialize Database**
11394

114-
Open a terminal console and change the project directory from `root` to `api` and run the following script:
95+
Open a terminal console and change the project directory from `root` to `api` and run the following command:
11596

11697
```
11798
sequelize db:create
99+
sequelize db:migrate
100+
sequelize db:seed:all
118101
```
119102

120-
To drop database, run the following script:
103+
To drop database, run the following command:
121104

122105
```
123106
sequelize db:drop
124107
```
125108

126-
### Docker
127-
128-
See **Bash Commands** below.
109+
See **Bash Commands** section for Docker.
129110

130111
## Bash Commands
131112

132113
From the `root` directory of the project, run the following commands:
133114

115+
Note: To view the Docker containers, open another terminal then enter `docker ps`. To manage separate Docker instance for API or client, open another terminal console and change the project directory from `root` to `api` or `client` and run the commands below.
116+
134117
### Docker
135118

136119
| Command | Description |
137120
|----------------------------------------|------------------------------------------------------------|
121+
| `./bin/install` | Build the Docker container and initialise database |
138122
| `./bin/start` | Build and run all the services (API, client, and database) |
139123
| `./bin/stop` | Stop all the services |
140124
| `./bin/console <container ID or Name>` | Access the terminal console of API or client container |
141125

142-
Note: To view the Docker containers, open another terminal then enter `docker ps`. To manage separate Docker instance for API or client, open another terminal window and change the project directory from `root` to `api` or `client` and run the commands above.
126+
Note: To manage separate Docker instance for API or client, open another terminal console and change the project directory from `root` to `api` or `client` and run the commands above.
143127

144128
### Database
145129

146-
**Local:**
130+
**Local**
147131

148132
| Command | Description |
149133
|---------------------------------------|------------------------------------------------------------|
150134
| `./bin/pg/local/start` | Start the PostgreSQL server (for Mac users only) |
151-
| `./bin/pg/local/initdb` | Initialise database with schema migration and data seeding |
152135
| `./bin/pg/local/resetdb` | Drop and re-initialise database |
153-
| `./bin/pg/local/dropdb` | Drop database |
154136
| `./bin/pg/local/migrate` | Run new schema migration |
137+
| `./bin/pg/local/migrateundo` | Revert the recent schema migration |
155138
| `./bin/pg/local/seed <seed file>` | Run specific data seed file with or without .js extension |
156139
| `./bin/pg/local/seedundo <seed file>` | Revert the seed of specific data seed file |
157140
| `./bin/pg/local/psql` | Access the database console |

api/.env.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PORT=7770
22
ALLOW_ORIGIN=http://localhost:7771
33
JWT_SECRET=jwtsecretcode
4-
POSTGRES_PORT=5432 # Do not change
5-
POSTGRES_DB=express_api_dev # Do not change
4+
POSTGRES_PORT=5432
5+
POSTGRES_DB=express_api_dev
66
POSTGRES_USER=express_api_user
77
POSTGRES_PASSWORD=root

api/README.md

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Express API Boilerplate
22
Required node version is `9.2.1`. The API app is powered by [Express](https://expressjs.com/) and [PostgreSQL](https://www.postgresql.org/) database.
33

4-
## Running the App
4+
## Starting the API App
55

6-
### Starting the app in local:
6+
Note: Only change the environment variables for `POSTGRES_USER` and `POSTGRES_PASSWORD` if working on local machine.
77

88
Open a terminal console and change the project directory from `root` to `api`. Copy `.env.dist` to `.env` and change the values of the environment variables if needed.
99

@@ -17,59 +17,85 @@ POSTGRES_USER=express_api_user
1717
POSTGRES_PASSWORD=root
1818
```
1919

20-
Note: Only change the environment variables for `POSTGRES_USER` and `POSTGRES_PASSWORD` if working on local machine.
21-
22-
Then run the following scripts in the terminal:
20+
Then run the following commands:
2321

2422
```
2523
yarn
2624
yarn start
2725
```
2826

29-
Access the client app at <http://localhost:7770>.
27+
Note: The database must be created and initialized after starting the app on fresh installation. See **Database using PostgreSQL and Sequelize** section. See **Bash Commands** section for Docker.
28+
29+
Access the app at <http://localhost:7770>.
30+
31+
## Docker
32+
33+
Download and install the [Docker Community Edition](https://www.docker.com/community-edition).
34+
35+
Note: See **Bash Commands** section for Docker.
36+
37+
## Database using PostgreSQL and Sequelize
38+
39+
**Installing PostgreSQL**
3040

31-
### Starting the App in Docker:
41+
**Mac:** [Getting Started with PostgreSQL on Mac OSX](https://www.codementor.io/engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb)
42+
<br>
43+
**Windows:** [Installing PostgreSQL, Creating a User, and Creating a Database](https://confluence.atlassian.com/display/CONF30/Database+Setup+for+PostgreSQL+on+Windows)
3244

33-
Download and install the [Docker Community Edition](https://www.docker.com/community-edition). With [Docker](https://www.docker.com/), both the API and client apps can be started using one script. First, do the same instructions above except for the `yarn`, `yarn start`, and `yarn global add detect-port` scripts. Then change directory to `root`, and run the following scripts in the terminal:
45+
NOTE: For Mac users, you can run the PostgreSQL server on a separate terminal console by running the following command:
3446

3547
```
36-
docker-compose build
37-
docker-compose up
48+
postgres -D /usr/local/var/postgres
3849
```
3950

40-
Note: The `docker-compose build` script is executed only once if the Docker image has not been created yet.
51+
**Create and Initialize Database**
4152

42-
To shutdown the app, press `CTRL+C` and run the following script in the terminal:
53+
Open a terminal console and change the project directory from `root` to `api` and run the following command:
4354

4455
```
45-
docker-compose down
56+
sequelize db:create
57+
sequelize db:migrate
58+
sequelize db:seed:all
4659
```
4760

61+
To drop database, run the following command:
62+
63+
```
64+
sequelize db:drop
65+
```
66+
67+
See **Bash Commands** section for Docker.
68+
4869
## Bash Commands
4970

50-
Change the project directory from `root` to `api` then run the following commands:
71+
From the `root` directory of the project, run the following commands:
72+
73+
Note: To view the Docker containers, open another terminal then enter `docker ps`. To manage separate Docker instance for API, open another terminal console and change the project directory from `root` to `api` and run the commands below.
5174

5275
### Docker
5376

54-
| Command | Description |
55-
|----------------------------------------|----------------------------------------------|
56-
| `./bin/start` | Build and run the api and database services |
57-
| `./bin/stop` | Stop all the services |
58-
| `./bin/console <container ID or Name>` | Access the terminal console of API container |
77+
| Command | Description |
78+
|----------------------------------------|-----------------------------------------------------|
79+
| `./bin/install` | Build the Docker containers and initialise database |
80+
| `./bin/start` | Build and run all the services (API and database) |
81+
| `./bin/stop` | Stop all the services |
82+
| `./bin/console <container ID or Name>` | Access the terminal console of API container |
5983

60-
Note: To view the Docker containers, open another terminal then enter `docker ps`. To manage separate Docker instance for API, open another terminal window and change the project directory from `root` to `api` and run the commands above.
84+
Note:
85+
86+
- To view the Docker containers, open another terminal then enter `docker ps`
87+
- To manage separate Docker instance for API, open another terminal console and change the project directory from `root` to `api` and run the commands above
6188

6289
### Database
6390

64-
**Local:**
91+
**Local**
6592

6693
| Command | Description |
6794
|---------------------------------------|------------------------------------------------------------|
6895
| `./bin/pg/local/start` | Start the PostgreSQL server (for Mac users only) |
69-
| `./bin/pg/local/initdb` | Initialise database with schema migration and data seeding |
7096
| `./bin/pg/local/resetdb` | Drop and re-initialise database |
71-
| `./bin/pg/local/dropdb` | Drop database |
7297
| `./bin/pg/local/migrate` | Run new schema migration |
98+
| `./bin/pg/local/migrateundo` | Revert the recent schema migration |
7399
| `./bin/pg/local/seed <seed file>` | Run specific data seed file with or without .js extension |
74100
| `./bin/pg/local/seedundo <seed file>` | Revert the seed of specific data seed file |
75101
| `./bin/pg/local/psql` | Access the database console |
@@ -80,6 +106,8 @@ Note: To view the Docker containers, open another terminal then enter `docker ps
80106
- The `start` command works only in local machine
81107
- Used `./bin/pg/psql <database container ID or Name>` to access the database console
82108

109+
Note: To run the commands above for separate API Docker instance, simply change the project directory from `root` to `api`. Same applies for local.
110+
83111
## Users
84112

85113
Use the following credentials to test different API responses. Default password for all accounts is `password`.

api/bin/console

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
source $PWD/../bin/bash.sh
3+
command=$(argsToCommand "$@")
4+
5+
execute docker exec -it $command /bin/bash

api/bin/pg/initdb renamed to api/bin/install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
source $PWD/../bin/bash.sh
33

4-
execute docker-compose run --rm database /bin/bash -c 'PGPASSWORD=root createdb -U express_api_user -h database express_api_dev'
4+
execute docker-compose build
55

66
$PWD/bin/run yarn
77
$PWD/bin/run node_modules/.bin/sequelize db:migrate

api/bin/pg/dropdb

Lines changed: 0 additions & 4 deletions
This file was deleted.

api/bin/pg/local/migrateundo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
source $PWD/../bin/bash.sh
3+
4+
execute sequelize db:migrate:undo

0 commit comments

Comments
 (0)