This is an application about api crud with nodejs, express, sequalize(ORM) and ansyc/await + PostgreSQL database.
Setting up an Express.js server
To set up a Express.js app server, create a directory for the project
mkdir test_2021 cd test_2021
We are going to install body-parser cors express pg pg-hstore sequelize.
npm install body-parser cors express pg pg-hstore sequelize and npm init -y or npm init
- tasks is table
- users is table
- view_users_tasks is view
- to run node server.js
- POST /api/users https://localhost:3000/api/users
- POST /api/assign https://localhost:3000/api/assign
- DELETE /api/unassign https://localhost:3000/api/unassign
- GET /api/tasks/common https://localhost:3000/api/tasks/common
git clone https://github.com/bedsongultom/test_2021.git
or
git clone [email protected]:bedsongultom/test_2021.git
C:\Program Files\PostgreSQL\9.6\bin>psql -U postgres
Password for user postgres:
psql (9.6.5)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=#
CREATE DATABASE test2012db;
CREATE TABLE tasks
(
tasks_id SERIAL,
tasks character varying(30),
users_id integer
)
CREATE TABLE users
(
users_id SERIAL,
users character varying(30)
)
CREATE OR REPLACE VIEW public.view_users_tasks AS
SELECT tasks.tasks_id,
tasks.tasks,
tasks.users_id,
users.users
FROM tasks
JOIN users ON tasks.users_id = users.users_id;