Skip to content

A comprehensive e-commerce application built with Node.js, Express.js, and MongoDB. Features include user authentication, product management, shopping cart functionality, order processing, and responsive design. Derived from the Udemy course by Maximilian Schwarzmüller.

License

Notifications You must be signed in to change notification settings

RamMichaeli17/Social-Blog

Repository files navigation

GitHub repo size GitHub language count Contributors Stargazers MIT License LinkedIn Gmail


Logo

Node.js REST API Social Network/Blog Application

This project is a full-featured social network and blog application built with Node.js, Express.js, and MongoDB. It serves as the backend for a full-stack application, providing core functionalities such as user authentication, data storage, and CRUD operations. Users can sign up, create posts, and view other posts, making it an engaging platform for social interaction and content sharing. The project also includes features like pagination, file uploads, and integration with REST APIs and GraphQL (an option), making it a comprehensive example of a Node.js application in a real-world context.

Visit the deployed backend application: Backend Deployment
Visit the deployed frontend application: Frontend Deployment
Note: Due to free tier limitations, expect delays on first load due to app sleep mode.

Note: This project is derived from the Udemy course NodeJS - The Complete Guide (MVC, REST APIs, GraphQL, Deno) by Maximilian Schwarzmüller.

Table of Contents
  1. About The Project
  2. Key Components and Features
  3. Learning Objectives
  4. Build Requirements
  5. Getting Started
  6. Deployment
  7. Usage
  8. License
  9. Contributors
  10. Contact

About The Project

image

This Node.js REST API Blog project simulates a functional social network and blog application where users can sign up and create posts. It covers the essential features of web development, including:

  • User Authentication: Secure user login and registration.
  • CRUD Operations: Create, read, update, and delete blog posts.
  • Data Persistence: Store data in a MongoDB database, using Mongoose for schema-based modeling.
  • Error Handling: Proper error responses for different scenarios.
  • Pagination: Efficiently handle large amounts of data by paginating blog post listings.
  • File Uploads: Allow users to upload images for their blog posts.
  • GraphQL Integration: Query and mutate blog data using GraphQL for more flexible APIs.

Technologies Used

This project employs a wide range of technologies and libraries to ensure a robust, efficient backend for the blog platform.

Core Technologies

  • Node.js: Backend runtime to handle HTTP requests and data processing.
  • Express.js: Web framework to set up routes and middleware.
  • MongoDB: NoSQL database for storing user and resource data.
  • Mongoose: ODM (Object Data Modeling) library for MongoDB and Node.js.
  • JWT: For implementing secure authentication using JSON Web Tokens.
  • Bcrypt.js: For hashing passwords.
  • dotenv: For managing environment variables.
  • Render: For deploying the application.

Dependencies

  • axios: Promise-based HTTP client for making requests to APIs.
  • body-parser: Middleware for parsing incoming request bodies in a middleware before your handlers, available under the req.body property.
  • compression: Middleware to compress response bodies for all requests.
  • express-validator: Middleware to validate and sanitize user inputs.
  • jsonwebtoken: Library for generating and verifying JSON Web Tokens (JWT).
  • multer: Middleware for handling multipart/form-data, used for uploading files.
  • socket.io: Library for enabling real-time, bidirectional communication between web clients and servers.

DevDependencies

  • chai: Assertion library for Node.js and browser that can be paired with any testing framework.
  • mocha: Test framework running on Node.js and in the browser to run asynchronous tests.
  • nodemon: Utility that monitors for any changes in your source and automatically restarts your server.
  • sinon: Library for creating spies, stubs, and mocks for JavaScript testing.

(back to top)

Key Components and Features

User Authentication

  • JWT Authentication: Secure user login with JSON Web Tokens.
  • Signup and Login: Users can register and log in securely.
  • Access Control: Restricts certain actions to authenticated users only.
  • Password Hashing: Passwords are stored securely using Bcrypt.js.

CRUD Operations

  • Create Resource: Create new records in the database (e.g., users, blog posts).
  • Read Resource: Retrieve stored data using GET requests.
  • Update Resource: Modify existing data with PUT/PATCH requests.
  • Delete Resource: Remove data from the database using DELETE requests.

Data Persistence with MongoDB

  • MongoDB: Stores user and resource data in a MongoDB database.
  • Mongoose: Handles database operations and data validation.

Error Handling

  • Error Responses: Provides proper error responses for different scenarios.

Pagination

  • Efficient Data Handling: Implements pagination for blog post listings to handle large amounts of data efficiently.

File Uploads

  • REST API File Upload: Allows users to upload images for their blog posts via REST API.
  • GraphQL File Upload: Enables file uploads using GraphQL for more flexible APIs.
  • ImageBB Integration: Utilizes ImageBB for hosting and managing uploaded images.

GraphQL Integration

  • Flexible APIs: Allows querying and mutating blog data using GraphQL.
  • Authentication in GraphQL APIs: Secure GraphQL endpoints using JWT for user authentication.

Real-Time Features with Websockets

  • Websockets Integration: Enables real-time updates and communication between clients and the server.

Automated Testing

  • Unit Tests: Implements unit tests using Mocha, Chai, and Sinon to ensure code reliability and correctness.

(back to top)

Learning Objectives

By completing this project, you will:

  • Set up a Secure REST API: Implement user authentication using JSON Web Tokens (JWT) to secure API endpoints.
  • Implement CRUD Operations: Create, read, update, and delete resources such as users and blog posts within a Node.js application.
  • Work with MongoDB and Mongoose: Utilize MongoDB for data storage and Mongoose for schema-based modeling and data validation.
  • Manage Environment Variables: Use dotenv to handle environment variables securely.
  • Enable File Uploads: Implement file upload functionality using Multer and manage uploaded images with ImageBB.
  • Integrate GraphQL: Set up a GraphQL server, define schemas and resolvers, and perform queries and mutations for flexible API interactions.
  • Handle Errors Gracefully: Implement robust error handling to provide meaningful error messages and responses.
  • Implement Pagination: Efficiently manage and display large data sets by implementing pagination.
  • Use Real-Time Features with Websockets: Enable real-time updates and communication between clients and the server using Socket.io.
  • Perform Automated Testing: Write and run unit tests using Mocha, Chai, and Sinon to ensure code reliability and correctness.
  • Deploy a Node.js Application: Learn how to deploy your Node.js application using Render, ensuring it's accessible and running in a production environment.

(back to top)

Build Requirements

  • Node.js (v14.x or later)
  • MongoDB: Local or Atlas instance.

(back to top)

Getting Started

Installation

  1. Clone the repository
git clone https://github.com/RamMichaeli17/Social-Blog.git
  1. Install NPM packages
npm install
  1. Set up environment variables - Create a .env file and add your credentials:
MONGO_DEFAULT_DATABASE=your_mongo_default_database
MONGO_PASSWORD=your_mongo_password
MONGO_USER=your_mongo_user
NODE_ENV=your_node_env
PORT=your_port
JWT_SECRET=your_jwt_secret

For the frontend project, create a .env file and include the following:

REACT_APP_API_BASE_URL=http://your-api-base-url.com
  1. Start the server
npm start

(back to top)

Usage

This project allows users to interact with a fully functional blog platform. Here's what users can do:

  • Register and Login: Users can sign up for a new account and log in to access personalized features.
  • Create Blog Posts: Authenticated users can create new blog posts, adding titles, content, and images.
  • Edit and Delete Blog Posts: Users can edit or delete their own posts, ensuring they have full control over their content.
  • View Blog Posts: All users (authenticated or not) can view blog posts. The blog posts are paginated to handle large amounts of data efficiently.
  • Comment on Posts: Authenticated users can add comments to blog posts, engage in discussions, and delete their own comments if necessary.
  • Search Posts: Users can search for specific blog posts by keywords, making it easier to find content.
  • GraphQL API: Developers can query and mutate blog data using the GraphQL API provided by the server.

Project Structure and Key Features

Here's a breakdown of the steps involved in building the blog project:

Setting Up the Project

  1. Project Initialization: Set up the Node.js project, install necessary dependencies (Express.js, MongoDB, etc.).
  2. Directory Structure: Organize folders and files for better project management.

User Authentication

  1. User Model: Create a User schema using Mongoose for MongoDB.
  2. Registration and Login: Implement routes and controllers for user signup and login.
  3. Authentication Middleware: Ensure certain routes are accessible only to authenticated users.

Blog Posts

  1. Post Model: Create a schema for blog posts.
  2. CRUD Operations: Implement routes and controllers for Creating, Reading, Updating, and Deleting blog posts.
  3. User Associations: Link blog posts to users so they can only edit or delete their own posts.

Comments

  1. Comment Model: Create a schema for comments.
  2. Comment Routes: Implement functionality for users to add, view, and delete comments on blog posts.

GraphQL Integration

  1. GraphQL Setup: Set up a GraphQL server using Apollo Server.
  2. Schemas and Resolvers: Define GraphQL schemas and resolvers for querying and mutating blog data.
  3. Testing GraphQL Queries: Use tools like GraphiQL to test your GraphQL API.

Additional Features

  1. File Uploads: Add functionality for users to upload images (e.g., for blog post thumbnails).
  2. Pagination: Implement pagination for blog post listings to handle large amounts of data.
  3. Search Functionality: Add a search feature to find blog posts by keywords.

Deployment

  1. Environment Setup: Set up environment variables for production.
  2. Deploying: Deploy your application to a cloud service (e.g., Heroku, AWS).

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contributors

Thanks to the following people who have contributed to this project:


Ram Michaeli

(back to top)

Contact

Ram Michaeli - [email protected]

Project Link: https://github.com/RamMichaeli17/Social-Blog

(back to top)

About

A comprehensive e-commerce application built with Node.js, Express.js, and MongoDB. Features include user authentication, product management, shopping cart functionality, order processing, and responsive design. Derived from the Udemy course by Maximilian Schwarzmüller.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published