andrevks / pure-nodejs-api

Pure JavaScript API w/ Streams & TDD. Efficient file uploads, regex, and CRUD operations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pure NodeJS API

Project OverviewKey FeaturesTechnologies UsedProject StructureInstallationUsageTesting

📄 Project Overview

This project is a comprehensive Node.js API implementation showcasing intermediate skills in pure JavaScript development. It demonstrates expertise in building a API from scratch, utilizing Node.js HTTP server, regex, Test-Driven Development (TDD) approach, and file uploads using streams.

It's a RESTful API designed to manage tasks. It provides various endpoints to perform CRUD (Create, Read, Update, Delete) operations on tasks. The API is built using pure Node.js, leveraging streams for efficient file uploads and regex to match routes params and query strings.

✨ Key Features

  • Task Management: Create, Read, Update, and Delete tasks.
  • File Upload: Import tasks from a CSV file using streams for efficient processing.
  • Validation: Validate uploaded files as CSV using MIME type check.
  • Error Handling: Handle and respond with appropriate error messages for invalid requests.
  • Test-Driven Development (TDD): Implement automated tests to ensure functionality and code coverage.

🛠 Technologies Used

  • JavaScript
  • Node.js
  • Busboy (for facilitating the parsing of multipart/form-data)
  • CSV Parser (for CSV file parsing)
  • Regex (for specific functionalities)
  • Vitest (similar to Jest) (for automated testing)

📁 Project Structure

  • routes.mjs: Defines the API routes and their corresponding handlers. Utilizes the TaskUseCase class to interact with the database and perform CRUD operations on tasks. Implements file upload functionality using the Busboy library to facilitate the parsing of multipart/form-data.
  • server.mjs: Initializes the HTTP server, sets up routes, and starts listening for incoming requests. Interacts with the Database class to establish a connection and handle database operations.
  • database.mjs: Implements the Database class responsible for bootstrapping the database connection.
  • middlewares/json-middleware.mjs: Provides middleware to parse JSON data in incoming requests.
  • use-cases/TaskUseCase.mjs: Implements the TaskUseCase class responsible for handling business logic related to tasks.

⚙️ Installation

  1. Clone the repository: git clone https://github.com/andrevks/pure-nodejs-api.git
  2. Navigate to the project directory: cd pure-nodejs-api
  3. Install dependencies: npm install

🖥 Usage

  1. Start the API server: npm run dev
  2. Access the API endpoints using a REST client (e.g., Postman, cURL) on http://localhost:3333.

🧪 Testing

Automated tests are implemented using the Vitest testing framework, which has a syntax similar to Jest. To run the tests, simply use the command npm test.


Made with 💜 by André Geraldo

About

Pure JavaScript API w/ Streams & TDD. Efficient file uploads, regex, and CRUD operations.


Languages

Language:JavaScript 83.6%Language:HTML 16.4%