App has been divided into 2 parts Express Node based Server and React based client.
server runs on port 3000
Client directory reside ./client . Client runs on port 3001 Client talks to server on port 3000
MySql DB details (no password)
user: "root",
database: "commenting"
- clone the repo
- clone the DB with .sql file
npm i
in root- start the server by
npm start
npm i
in /client directory- start the client by
npm start
- open localhost:3001 to see the demo.
Post
id
content
Comment
id
Parent: PostId | Comment id
content
userId
Server side API is served with 4 operations
-
get-id
gets all comments with parent id id provided -
delete
deletes the comment with provided id -
update
updates the comment with provided id and content -
create
creates a new comment provided content and parent (also used for replying)It USes Mysql to store and query the data and provides response in JSON format
Client has Main React Component as APP
Which renders the initial comment as static Post.
Comment
component requires props
- id- unique id
- userId- user who created that comment
- content
- onUpdate - call back function when update is done.
It makes call to server based on its id
and fetches child comment
renders itself and recursively children make call and render themselves.