Files
2020-12-11 08:42:05 +00:00

82 lines
1.6 KiB
Markdown

# BioProAPIServer
### Setup pi3 postgresql
##### Switch to the Postgres user to configure the database
```
sudo su postgres
```
##### Create a database user 'biopro' with password 'BioProControlBox'
```
createuser biopro -P --interactive
```
##### Postgres command (type psql first to connect postgres)
```
#Find databases
\l
#Find tables
\dt
```
### Run apiServer on device
##### Clone project
```
git clone https://gitlab.com/bioproscientific/bioproapiserver.git
```
##### Change config port
```
cd ~/bioproapiserver/src
vim config.js
```
change the code following as:
```
/*
change apiserver port to postgres port, 54321 --> 5432 (default)
*/
export const pgDB = {
host: '127.0.0.1', // 服务器地址
port: 54321, // 数据库端口号 -----------------> 5432
username: 'biopro', // 数据库用户名
password: 'BioProControlBox', // 数据库密码
database: 'postgres' // 数据库名称
}
```
##### Init setup project && build dist app
```
cd ~/bioproapiserver
npm install
npm run build
```
###### Auto run program when pi-start
```
sudo vim /etc/rc.local
```
add the code following as:
```
nohup node /home/pi/bioproapiserver/dist/app.js > /home/pi/.api_server.out &
```
### Localhost develop
##### Localhost test port binding (your device:54321 -> raspberrypi:5432)
```
ssh -NL 54321:localhost:5432 pi@your-pi3-ip
```
##### Run apiServer on your localhost (remember binding port first)
```
git clone https://gitlab.com/bioproscientific/bioproapiserver.git
cd bioproapiserver
npm install
npm run start
```
##### References
>https://opensource.com/article/17/10/set-postgres-database-your-raspberry-pi