https://github.com/riascho/postgres-node-express-api-example
A RESTful API built with Node.js, Express, and PostgreSQL
https://github.com/riascho/postgres-node-express-api-example
express node-postgres nodejs postgresql restful-api
Last synced: 10 months ago
JSON representation
A RESTful API built with Node.js, Express, and PostgreSQL
- Host: GitHub
- URL: https://github.com/riascho/postgres-node-express-api-example
- Owner: riascho
- Created: 2025-01-26T16:07:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-02T12:49:19.000Z (12 months ago)
- Last Synced: 2025-02-02T13:39:54.530Z (12 months ago)
- Topics: express, node-postgres, nodejs, postgresql, restful-api
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node.js Express PostgreSQL API
A RESTful API (user database) built with Node.js, Express, and PostgreSQL to demonstrate a basic example setup.
**Reference**: https://blog.logrocket.com/crud-rest-api-node-js-express-postgresql
## Database Connection
This app uses [node-postgres](https://node-postgres.com/) to connect to PostgreSQL using `pg.Pool`. Connection parameters are read from environment variables.
## Setup
Create an `.env` file in the root directory with the following PostgreSQL configuration:
| Key | Description |
| ------------ | ------------------------------ |
| `PGUSER` | postgres role |
| `PGPASSWORD` | role password |
| `PGDATABASE` | postgres database |
| `PGHOST` | postgres host (e.g. localhost) |
| `PGPORT` | postgres port (e.g. 5432) |
## Running the App
Install dependencies:
```sh
npm install
```
Start the server:
```sh
npm start
```
Launch in Development:
```sh
npm dev
```
The API will be available at [http://localhost:3000](http://localhost:3000).
## Available Endpoints
- `GET /` - API information
- `GET /users` - Get all users
- `GET /users/:id` - Get user by ID
- `POST /users` - Create new user
- `PUT /users/:id` - Update user
- `DELETE /users/:id` - Delete user
## Additional Notes
Edge cases and error handling has been neglected for simplicity.