Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cynthiawahome/node-basic-sequelize-orm
A beginner-friendly hands-on example demonstrating how to use Sequelize ORM with Node.js to perform basic CRUD operations. Learn to manage database interactions easily with JavaScript models.
https://github.com/cynthiawahome/node-basic-sequelize-orm
Last synced: 10 days ago
JSON representation
A beginner-friendly hands-on example demonstrating how to use Sequelize ORM with Node.js to perform basic CRUD operations. Learn to manage database interactions easily with JavaScript models.
- Host: GitHub
- URL: https://github.com/cynthiawahome/node-basic-sequelize-orm
- Owner: CynthiaWahome
- Created: 2024-08-04T09:41:37.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-08-04T09:55:35.000Z (3 months ago)
- Last Synced: 2024-08-04T10:56:32.528Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# **Getting Started with Sequelize ORM and Node.js**
This project provides a hands-on introduction for beginners to learn how to integrate Sequelize ORM with Node.js and Express.js.
**Introduction**
Sequelize is an ORM for Node.js that simplifies database interactions by using JavaScript objects instead of SQL queries. It supports databases like MySQL, PostgreSQL, SQLite, and MariaDB.
With Sequelize, you define models to represent your data and perform CRUD operations. This abstraction makes managing and querying data easier, so you can focus on building your application.
## Setup Instructions
1. **Initialize Project**
- Create a new directory and navigate into it.
- Run `npm init -y` to initialize a Node.js project.
- Install dependencies:
```bash
npm install express sequelize mysql2 path fs
```2. **Create Configuration File**
- Create `config/config.json` and configure your database connection.3. **Define Model**
- Create `models/user.js` to define your Sequelize model for `User`.4. **Set Up Express Server**
- Create `index.js` for setting up Express.js and Sequelize:
- Define routes for CRUD operations (`GET`, `POST`, `DELETE`).
- Sync models with the database and start the server.5. **Run the Application**
- Ensure MySQL server is running.
- Start your Node.js server:
```bash
node index.js
```6. **Test Endpoints**
- Use tools like `curl` or Postman to test CRUD operations:
- Retrieve users: `GET /select`
- Insert a user: `POST /insert`
- Delete a user: `DELETE /delete/:id`## Notes
- Use `mysql2` as the database driver in your project.
- Update configuration details with your MySQL credentials.
- For more details, check the official documentation:
- [Sequelize Documentation](https://sequelize.org/)
- [Express.js Documentation](https://expressjs.com/)