Skip to content

BenjaminGERARD2006/API2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Js App

Introduction

This project is a secure REST API built with Node.js and Express for managing student records. It implements JWT (JSON Web Token) authentication to protect endpoints and ensure that only authorized users can access and manipulate student data. The API follows RESTful principles, providing a clean and intuitive interface for CRUD (Create, Read, Update, Delete) operations on student resources.

Requirements

Runtime & Core Dependencies:

  • Node.js (v18 or higher recommended)
  • Express.js - Web framework for routing and middleware
  • JSON Web Tokens (jsonwebtoken) - For authentication
  • bcryptjs - Password hashing and verification
  • cors - Cross-Origin Resource Sharing support
  • dotenv - Environment variable management

Database:

  • SQLite (lightweight option for development/small deployments)

Development Tools:

  • nodemon (optional) - Auto-restart server during development
  • Git - Version control

Deployment:

  • Render account (free tier available)
  • Environment variables configured on Render dashboard

Environment Variables Required:

PORT=3000
JWT_SECRET=your-super-secret-key-change-this
JWT_EXPIRES_IN=24h
DATABASE_URL="./data/db.sqlite"
API_KEY=your-api-key-for-endpoint-protection
NODE_ENV=production

Folder Structure

API/
├── node_modules/ # Project dependencies (auto-generated, not in version control)
├── src/ # Source code directory
│ ├── controllers/ # Business logic and request handlers
│ │ └── authController.js # Handles authentication logic
│ │
│ ├── middleware/ # Custom middleware functions
│ │ └── auth.js # JWT verification middleware
│ │ └── validate.js # Input validation middleware
│ │ └── errorHandler.js # Global error handling
│ │
│ ├── models/ # Data models and schemas
│ │ └── User.js # User authentication model
│ │
│ ├── routes/ # API route definitions
│ │ └── studentRoutes.js # Student-related endpoints
│ │ └── authRoutes.js # Authentication endpoints
│ │
│ ├── services/ # Business logic and database operations
│ │ └── authService.js # Authentication services
│ │
│ └── index.js # Main application entry point
│
├── .env # Environment variables (NOT in version control)
├── .gitignore # Specifies files to ignore in version control
├── package-lock.json # Locked versions of dependencies
├── package.json # Project metadata and dependencies
└── README.md # Project documentation

Before starting the project, create a JavaScript file in an empty folder and open it with VS Code. In the terminal, run Node followed by the file name to launch it. If you don't have Node, you can install it by following this link:

First steps

Start an Express server

Data flow and middleware

Project structure

Controllers

Service Layer

Express Router

Database: SQLite

Models

Environment Variables

Deploy to Render

Your Turn !

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages