Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonathanguez/nodejs_restapi
Simple Restful API
https://github.com/yonathanguez/nodejs_restapi
Last synced: about 1 month ago
JSON representation
Simple Restful API
- Host: GitHub
- URL: https://github.com/yonathanguez/nodejs_restapi
- Owner: YonathanGuez
- Created: 2020-05-28T19:02:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T02:58:27.000Z (almost 2 years ago)
- Last Synced: 2023-02-28T04:38:36.497Z (almost 2 years ago)
- Language: JavaScript
- Size: 1.99 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nodejs_restapi
Simple Restful API with PostgreSQL:
- Create
- Login
- Delete
- Update
- Script Test API End Point: jestWe will use PostgreSQL Manually or with automation script
## Install all dependencies
```
yarn
```## Config Postgres:
.env:
```
DATABASE_URL="postgressql://{USER}:{PASSWORD]@{HOST}:{PORT_DB}/{NAME_DB}"
USER_DB="{USER}"
PORT=3000
```### Installing DB:
#### How to Use Postgresql Automation Tables:
I put a model of my db in db/db.sql
init.js will change the username and run this into your postgresRun : that will call db/ini.js with createDB
```
yarn test
```#### How to Use Postgresql Manually :
##### Build auto-increment :
##### Build Contraint like Unique :
##### Clean a table or DB :
#### Export DB from Pgadmin4:
```
Backup> - Format "Plan"
- Encoding "UTF8"
- Role name "Postgres"
```## Postman :
add collection app_user.postman_collection.json
## Action RESTFUL API :
```
yarn start
```http://localhost:3000/api/users/createuser
http://localhost:3000/api/users/login
http://localhost:3000/api/users/deleteuser
http://localhost:3000/api/users/updatepayment## Test API End Point With jest
```
yarn test
```## Attention on windows Docker work on an other IP :
Like 192.168.99.100 for me in my Local
## Dockerization :
### Simple Dockerfile:
Run only server with Docker file :
```
docker build -t test:1 .
docker run -it -p 3000:3000 test:1
```enter in the container
```
docker run -it -p 3000:3000 test:1 sh
```Run Postgres :
```
docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=root -d postgres
```### Docker-compose :
build first time :
```
docker-compose up
```or
build first time in background:
```
docker-compose up -d
```Run service :docker-compose run '<'service'>'
```
docker-compose run app_restapi
```rebuild the image:
```
docker-compose build
```Stop the service :
```
docker-compose down
```##### Docker-compose command :
docker-compose ps
docker-compose images