https://github.com/victorbadaro/node-api-rawsql-example
An example NodeJS API that uses raw SQL
https://github.com/victorbadaro/node-api-rawsql-example
api api-rest backend node postgres raw-sql sql
Last synced: 9 months ago
JSON representation
An example NodeJS API that uses raw SQL
- Host: GitHub
- URL: https://github.com/victorbadaro/node-api-rawsql-example
- Owner: victorbadaro
- Created: 2021-12-23T14:27:30.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-08-22T02:54:53.000Z (over 2 years ago)
- Last Synced: 2025-01-30T07:13:50.011Z (11 months ago)
- Topics: api, api-rest, backend, node, postgres, raw-sql, sql
- Language: JavaScript
- Homepage:
- Size: 76.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-api-rawsql-example
[](./LEIAME.md)
## Summary
- [π§Ύ About](#-about)
- [π Main technologies](#-main-technologies)
- [π» Usage](#-usage)
- [π Requests](#-requests)
## π§Ύ About
This project was made to be a simple example of a back-end application using raw SQL (no ORMs or Query builders)
## π Main technologies
- [Node.js](https://nodejs.org/)
- [Express](https://expressjs.com/)
- [PostgreSQL](https://www.postgresql.org/)
- [Babel](https://babeljs.io/)
- [Nodemon](https://nodemon.io/)
_(You can see all the dependencies in the [package.json](./package.json) file)_
## π» Usage
As you can see on [π Main technologies](#-main-technologies) topic, this application depends on a postgreSQL database, so you must have it installed.
First things first:
1. Clone the project (you'll need a [personal access token](https://docs.github.com/pt/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls)):
```bash
$ git clone https://github.com/victorbadaro/node-api-rawsql-example.git
```
2. Access its directory:
```bash
$ cd node-api-rawsql-example
```
3. Install its dependencies:
```bash
$ yarn
# feel free to use another package manager, but you might want use yarn once there's already a yarn.lock file in the root directory
```
4. Access your PostgreSQL server and create the database (you can use any name):
```sql
CREATE DATABASE node_api_rawsql_db;
```
5. Run the SQL commands that is in [database.sql](./database.sql) file
6. Create a `.env` file in the root directory with the same content that is in the [.env.example](./.env.example) file and fill the variables with your own data:
For example:

7. Start the server by running the `dev` script:
```bash
yarn dev
```
## π Requests
Now the server is ready to receive your requests! There's a [request collection](./request_collection.json) in the root directory so you can use (use [insomnia](https://insomnia.rest/) to import the collection). Remember to inform the server port in the `baseUrl` environment variable!
Here are the requests you can make:
- GET /users
- POST /users
```json
{
"name": "",
"email": ""
}
```
- GET /users/:id
- PUT /users/:id
```json
{
"name": "",
"email": ""
}
```
- DELETE /users/:id
- GET /products
- POST /products
```json
{
"description": "",
"user_id":
}
```
- GET /products/:id
- PUT /products/:id
```json
{
"description": ""
}
```
- DELETE /products/:id
---
This project was created and developed with β€ by Victor BadarΓ³