Skip to content

📋 PostgreSQL database used with nodejs and express to create a REST API

Notifications You must be signed in to change notification settings

AndrewJBateman/postgresql-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ PostgreSQL Rest API

  • 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

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

📄 Table of contents

📚 General info

  • 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

📷 Screenshots

screen print

📶 Technologies

💾 Setup

  • Create PostgreSQL database and add access credentials to your own src/routes/config.ts file (see config.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 server localhost: 3000
  • Run npm run build to compile app

💻 Code Examples

  • 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);
};

🆒 Features

  • PostgreSQL access credentials hidden from GitHub in config file
  • Postman used to perform CRUD operations on PostgreSQL database

📋 Status & To-do list

  • Status: Fully working basic CRUD app
  • To-do: nothing

👏 Inspiration

📁 License

  • N/A

✉️ Contact

Releases

No releases published

Packages

No packages published