- App using nodejs with express middleware to connect to a PostgreSQL database and make Create, Read, Update & Delete (CRUD) operations of user data
- Note: to open web links in a new window use: ctrl+click on link
- General info
- Screenshots
- Technologies
- Setup
- Code Examples
- Features
- Status
- Inspiration
- Licence
- Contact
- PostgreSQL needs to be installed and running - I started it from my Windows 10 PostgreSQL 12 dropdown option 'SQL shell (psql)'
- PostgreSQL shell commands:
\l
list all databases.\c database1
connect to database1.\dt
inspect tables.\d users
see detail of table with name users.\q
to quit. - Src (source) folder contains raw code in typescript. Dist (distribution) folder will contain minified/concatenated javascript code for production
- tsc --watch command used to run local compiler in watch mode
- PostgreSQL v12 database
- PostgreSQL Installer for Windows
- Express.js middleware v4
- Postman to perform CRUD operations on backend database
- Create PostgreSQL database and add access credentials to your own
src/routes/config.ts
file (seeconfig.example.ts
) - Add a
/dist
folder at same level as/src
folder - Run
npm install
to install dependencies - Run
npm run dev
to compile app and connect to serverlocalhost: 3000
- Run
npm run build
to compile app
- code to fetch a user from the Postgres database using id
export const getUserById = async (
req: Request,
res: Response
): Promise<Response> => {
const id = parseInt(req.params.id);
const response: QueryResult = await pool.query(
"SELECT * FROM users WHERE id = $1",
[id]
);
return res.json(response.rows);
};
- PostgreSQL access credentials hidden from GitHub in
config
file - Postman used to perform CRUD operations on PostgreSQL database
- Status: Fully working basic CRUD app
- To-do: nothing
- N/A
- Repo created by ABateman, email: gomezbateman@yahoo.com