API and database for Zidence Project using Express and PostgreSQL
- Node.js
- Express
- Sequelize
- PostgreSQL
This project is Zidence's REST API. Built using express with ORM sequelize PostgreSQL. The migration and seed are set with steps written in this README. The auth endpoints is implemented with hashed password using bcrypt and token using jsonwebtoken. Other endpoints is also secured by API-Key.
HTTP | Endpoint | Description |
---|---|---|
GET |
/ |
Show info message |
Endpoint | HTTP | Description | Header |
---|---|---|---|
/auth/register |
POST |
Register new user | |
/auth/login |
POST |
Login to existing user | Authorization: bearer token |
/auth/logout |
POST |
Logout the authenticated user | Authorization: bearer token |
/auth/:username |
GET |
Show authenticated user data | Authorization: bearer token |
HTTP | Endpoint | Description | Header |
---|---|---|---|
GET |
/users |
Get all users name | X-API-Key |
GET |
/users/:username |
Get public information of certain user |
HTTP | Endpoint | Description | Header |
---|---|---|---|
GET |
/items |
Get all tasks and its user | X-API-Key |
GET |
/items/:id |
Get task by id and show its subtasks | X-API-Key |
GET |
/items/list?{query} |
Get task queried by time or location | Authorization: bearer token |
POST |
/items |
Add new task by single string | Authorization: bearer token |
yarn
npm install --global sequelize-cli
yarn global add sequelize-cli
After installing dependencies, .env
file will be automatically generated.
Edit the .env
file according to your database configuration.
From this:
DB_USERNAME=
DB_PASSWORD=
DB_DATABASE=
DB_HOST=
DB_DIALECT=
SECRET_KEY=
API_KEY=
To something like this:
DB_USERNAME=username
DB_PASSWORD=secret_password
DB_DATABASE=database_name
DB_HOST=localhost
DB_DIALECT=postgres
SECRET_KEY=your_secret_key_jwt
API_KEY=your_x_api_key
$ createdb database_name
yarn migrate
# it will run
# sequelize db:migrate
yarn seed
# it will run
# sequelize db:seed:all
yarn dev
yarn start
Copy and paste all environment variables.
heroku run npm install -g yarn -a app-name
heroku run yarn -a app-name
heroku run yarn migrate -a app-name
heroku run yarn seed -a app-name
MIT