|
18 | 18 | - `sudo apt update`
|
19 | 19 | - `sudo apt install postgresql postgresql-contrib`
|
20 | 20 |
|
21 |
| -###### 2. Install sequelize-cli: |
22 |
| -- `sudo npm install -g sequelize-cli` |
23 |
| - |
24 |
| -###### 3. Create db and admin user: |
| 21 | +###### 2. Create db and admin user: |
25 | 22 | - Before run and test connection, make sure you have created a database as described in the above configuration. You can use the `psql` command to create a user and database.
|
26 |
| - - `psql postgres --u postgres` |
27 |
| - |
28 |
| -- Next, type this command for creating a new user with password then give access for creating the database. |
29 |
| - - `postgres-# CREATE ROLE admin WITH LOGIN PASSWORD 'admin_pass';` |
30 |
| - - `postgres-# ALTER ROLE admin CREATEDB;` |
31 |
| - |
32 |
| -- Quit `psql` then log in again using the new user that previously created. |
33 |
| - - `postgres-# \q` |
34 |
| - - `psql postgres -U admin` |
| 23 | + - `psql -U postgres` |
35 | 24 |
|
36 | 25 | - Type this command to creating a new database.
|
37 |
| - - `postgres=> CREATE DATABASE nodejs_backend_db;` |
38 |
| - |
39 |
| -- Then give that new user privileges to the new database then quit the `psql`. |
40 |
| - - `postgres=> GRANT ALL PRIVILEGES ON DATABASE nodejs_backend_db TO admin;` |
| 26 | + - `postgres=> CREATE DATABASE development OWNER postgres;` |
41 | 27 | - `postgres=> \q`
|
42 |
| - |
43 |
| -###### 4. Run db migrations and seeds: |
44 |
| - - `sequelize db:migrate && sequelize db:seed:all` |
45 | 28 |
|
46 | 29 | ------------
|
| 30 | + |
| 31 | + ##### Setup database tables: |
| 32 | + - `yarn reset` |
47 | 33 |
|
48 | 34 | ##### Start development build:
|
49 | 35 | - `yarn start:dev`
|
50 |
| - |
| 36 | + |
51 | 37 | ##### Start production build:
|
52 |
| - - `yarn start` |
| 38 | + - `yarn start` |
| 39 | + |
| 40 | + ------------ |
| 41 | + |
| 42 | + #### Api Documentation (Swagger) |
| 43 | + |
| 44 | + http://localhost:8080/api-docs (local host) |
| 45 | + |
| 46 | + http://host_name/api-docs |
| 47 | + |
| 48 | + ------------ |
| 49 | + |
| 50 | + ##### Docker: |
| 51 | + |
| 52 | + See instructions in a `docker` folder if you want to run this backend alongside with a frontend and a database. |
| 53 | + In this case you don't need to build docker image manually and run commands below. |
| 54 | + |
| 55 | + 1. Make sure you have Postgres installed locally like in [Adjust local db](#adjust-local-db): |
| 56 | + 2. Build an image `docker build -t um-backend-image .` |
| 57 | + 3. Run a container `docker run -p 8080:8080 -d um-backend-image` |
| 58 | + 4. Now the api should be available by `http://localhost:8080/api` |
0 commit comments