Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/victorbadaro/node-api-sequelize-example

An example NodeJS API that uses the sequelize ORM
https://github.com/victorbadaro/node-api-sequelize-example

api api-rest backend node orm postgres sequelize sql

Last synced: 15 days ago
JSON representation

An example NodeJS API that uses the sequelize ORM

Awesome Lists containing this project

README

        

# node-api-sequelize-example

[![LEIAME.md](https://img.shields.io/badge/-Leia%20em%20Portugu%C3%AAs-brightgreen?style=for-the-badge)](./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 the Sequelize ORM

## πŸš€ Main technologies
- [Node.js](https://nodejs.org/)
- [Express](https://expressjs.com/)
- [PostgreSQL](https://www.postgresql.org/)
- [Sequelize](https://sequelize.org/)
- [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-sequelize-example.git
```

2. Access its directory:
```bash
$ cd node-api-sequelize-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. 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:

![image](https://github.com/victorbadaro/node-api-sequelize-example/assets/9096344/3d3cf42d-0d09-4b7e-9092-337097495b75)

5. Create the database by running (your postgreSQL server must be running):
```bash
$ yarn sequelize db:create
```

6. Run all the migrations to create the database relations:
```bash
$ yarn sequelize db:migrate
```

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ó