Skip to content

wrujel/rest-api-et

Repository files navigation

demo status test

REST API with Express and TypeScript

TypeScript Express Node.js MongoDB Mongoose Angular Angular Material

REST API built with Express and TypeScript featuring user authentication, product CRUD operations, and an Angular 17 frontend with Angular Material. Uses MongoDB for data persistence.

Demo · Report issue · Suggest something

Table of Contents

Features

  • User registration and login with session token authentication
  • Password hashing with HMAC SHA-256 and random salt
  • Session token stored in cookies for authentication
  • CRUD operations for products (create, read, update, delete)
  • CRUD operations for users (read, update, delete)
  • Ownership middleware to protect product modifications
  • Authentication middleware for protected routes
  • Angular 17 standalone frontend with Angular Material UI
  • Auth guard and HTTP interceptor for frontend authentication
  • Reactive forms for product management
  • MongoDB with Mongoose ODM
  • TypeScript on both backend and frontend
  • Hot reload with Nodemon during development

Tech Stack

Getting Started

Prerequisites

  • Node.js 18+
  • npm
  • A MongoDB instance (local or MongoDB Atlas)

Installation

git clone https://github.com/wrujel/rest-api-et.git
cd rest-api-et
npm install
cd frontend/angular
npm install
cd ../..

Running locally

npm run dev

Open http://localhost:8080 with your browser to see the result.

Build

npm run build

Environment Variables

To run this project, you will need to add the following environment variables to your .env file.

Variable Description Required
MONGO_URL MongoDB connection string Yes
SECRET Secret key used for HMAC password hashing Yes
PORT Server port (defaults to 8080) No
FRONTEND_BUILD_PATH Path to the Angular frontend build output No
ENVIRONMENT Set to development to enable session token in login response and header-based auth No

Project Structure

/
├── public/
│   └── screenshot.png
├── src/
│   ├── controllers/
│   │   ├── authentication.ts
│   │   ├── products.ts
│   │   └── users.ts
│   ├── db/
│   │   ├── product.ts
│   │   └── users.ts
│   ├── helpers/
│   │   └── index.ts
│   ├── middlewares/
│   │   └── index.ts
│   ├── router/
│   │   ├── authentication.ts
│   │   ├── index.ts
│   │   ├── products.ts
│   │   └── users.ts
│   └── index.ts
├── frontend/
│   └── angular/
│       └── src/
│           └── app/
│               ├── components/
│               │   ├── api-card/
│               │   ├── home/
│               │   ├── login/
│               │   ├── navbar/
│               │   └── register/
│               ├── models/
│               ├── services/
│               └── app.routes.ts
├── package.json
├── tsconfig.json
└── nodemon.json

Demo

You can check out the demo:

Demo

API Reference

Method Endpoint Description Auth Required
POST /api/auth/register Register a new user No
POST /api/auth/login Login and get session token No
GET /api/users List all users Yes
DELETE /api/users/:id Delete a user by ID Yes (Owner)
PATCH /api/users/:id Update a user's username Yes (Owner)
GET /api/products List all products Yes
POST /api/products Create a new product Yes
PUT /api/products Update a product (id via query param) Yes (Owner)
DELETE /api/products Delete a product (id via query param) Yes (Owner)

Contributing

Contributions are welcome! If you have suggestions or find bugs, please open an issue or submit a pull request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License.


About

REST API developed with Express, Angular, Typescript and Mongodb

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Sponsor this project

  •  

Contributors