Skip to content

aRav3n/messenger-backend

Repository files navigation

Messenger Project Backend

Table of Contents

Description

This is the RESTful API created for my messenger app as a part of The Odin Project curriculum (Full Stack JavaScript track). It is built using Node.js and Express with a PostgreSQL database managed using Prisma ORM.

Installation Instructions

  1. Clone or fork this repo
  2. cd into the project root directory (where the README.md file is located)
  3. Run the following in your terminal
    • npm init -y
      
      npm install @prisma/client @prisma/extension-accelerate bcryptjs
      npm install cors dotenv express
      npm install express-validator jsonwebtoken pg
      
      npm install @types/node jest prisma --save-dev
      npm install supertest tsx typescript --save-dev
  4. Create a .env file
    • NODE_ENV=development
      TEST_DATABASE_URL="your_local_test_database_url"
      DATABASE_URL="your_local_database_url"
      SECRET_KEY="your_secret_key"
      PORT=3000 (or any 4 digit even integer)
  5. npm run dev
    • ^ + c will end the process
  6. After making updates to ./src/queries.ts you'll want to run this to recompile queries.js
    • npx tsc

Usage and Screenshots

The API can be used by using the endpoints listed below.

API Usage:

  • User Routes
    • Sign up
      • POST /user/signup 1
    • Log in
      • POST /user/login 2
    • Delete account
      • DELETE /user/:userId/delete 3
  • Friend Routes
    • Add friend
      • POST /friend 4
    • List friends
      • GET /friend/:userId 5
    • Delete friend
      • DELETE /friend/friendId 6
  • Message Routes
    • Send a message
      • POST /message/:friendId 7
    • List message thread for a friendship
      • GET /message/friend/:friendId 8
    • Delete a message
      • DELETE /message/:messageID 9

Route Notes

Features

  • Uses CORS to verify that the domain requesting access is valid
  • Routes are fully tested

Technologies Used

Backend

Development Tools

Hosting

Dependencies and Credits

Package Dependencies

Other Credits

Project Structure

├──controllers/            # Controller files
├──db/                     # Compiled queries.js file located here
├──generated/              # Generated Prisma files
├──prisma/                 # Prisma models and migrations
├──routes/                 # Router files
├──src/                    # Raw uncompiled queries.ts file located here
└──test/                   # Test files located here

Footnotes

  1. Expects { name, password, confirmPassword }. Returns { id, name, hash }.

  2. Expects { name, password }. Returns { token } property which contains the JSON Web Token for the user.

  3. Requires auth header. Expects { name, password }. Sends a status code 200.

  4. Requires auth header. Expects { name }. Returns status 200 and { message: "New friendship with name added!" }.

  5. Expects only the user's id in the URL. Returns an array of user objects (see note 1 above).

  6. Requires auth header. Expects { name }. Returns { id, userAId, userBId } for the deleted friendship.

  7. Requires auth header. Expects { message }. Returns { id, senderId, receiverId, messageBody }.

  8. Requires auth header. Expects only the friend's id in the URL. Returns an array of message objects (see note 7 above).

  9. Requires auth header. Expects only the message id in the URL. Returns message object (see note 7 above).

Releases

No releases published

Packages

 
 
 

Contributors