Skip to content

ritwikpal20/Basic-Blog-Media-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a api based , simple backend project , based on blog posting. It works on single URL and all the various components are loaded into it asynchronously.

Blog Posting App

Setting up the database on local machine for development:

Using MySQL Database

1. Install Mysql Database and add it to path

2.Setup the Database

  • Using shell, login in as root user
 $ mysql -u root -p
  • Create a database
$ create database  socialmediadb;
  • Create a user and assign a password
$ create user socialuser identified by 'socialpass';
  • Grant privileges on new user
$ grant all privileges on socialmediadb.* to socialuser;
  • Flush privileges for changes to take effect
$ flush privileges;

Using SQLite Database

This project by default uses SQLite Database on development server, which does needs to be set up. It works on directly.

Starting the project:

Clone the codebase from github

  • Open the editor terminal
$ npm install
$ npm start
  • Project Structure
SRC
│   server.js
│
├───controllers
│       comments.js
│       posts.js
│       users.js
│
├───db
│       models.js
│       socialmediadb.db
│
├───public
│   │   index.html
│   │
│   ├───app
│   │       all-articles.js
│   │       comment.js
│   │       common.css
│   │       common.js
│   │       login.js
│   │       my-post.js
│   │       navbar.js
│   │       profle.js
│   │       signup.js
│   │       write-post.js
│   │
│   ├───components
│   │       all-articles.html
│   │       comments.html
│   │       footer.html
│   │       login.html
│   │       my-post.html
│   │       navbar.html
│   │       profile.html
│   │       signup.html
│   │       write-post.html
│   │
│   ├───css
│   ├───fonts
│   └───js
│           jquery-3.5.1.js
│
└───routes
    ├───posts
    │       comment.js
    │       index.js
    │
    └───users
            index.js

API Documentation

  • GET : /api/users/{userId or username} - Finds the user with given username or id , passed in the params of the request.

  • POST : /api/users/ - Creates a new user with name,username,email and password , passed in the body of the request.

  • GET : /api/posts/ - Returns all the posts that have been already created.

  • POST : /api/posts/ - Creates a new post with following fields in the body(title,body,userId)

  • GET : /api/posts/comments/ - shows comments with either a userId or postId passed in the query of the request . If want to get all comments by a particular user pass the userId with postId as null. If want to get all comments under a post pass the userId as null and postId with a value. {userId: _ , postId: _ }

  • POST : /api/posts/comments/ - post a comment under a particular post with a given user . The body of the post , userId and postId are to be passed in the body of the req

  • POST : /api/posts/delete/ - deletes a post with a postId passed in query of request

  • GET : /api/posts/post/ - sends a post with a postId passed in query of request

  • POST : /api/posts/post/ - updates a post with a postid , title and body passed in body of request

About

My first attempt to create a node.js project , where users can login to write, edit ,delete and comment on posts .

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published