Git Product home page Git Product logo

react_express_chat's Introduction

React Express Chat App

Full stack app with React and Express. Run client and server concurrently.
Preview client-only build: https://imarvin.github.io/react_express_chat/

Quick Start

Make sure you have Node.js installed (https://nodejs.org).

Open terminal and run the following commands inside the app folder(/better_chat)

1. npm install 
2. npm run client-install
3. npm run dev

On your browser go to this address to see the app: 
http://localhost:3000


bash
# Install dependencies for server
npm install

# Install dependencies for client
npm run client-install

# Run the client & server with concurrently
npm run dev

# Run the Express server only
npm run server

# Run the React client only
npm run client

# Server runs on http://localhost:5000 and client on http://localhost:3000

App Info

This is a simple chat app that fetches data from a json file. New chat messages does not persist.

Express Server - ./server.js
React - ./client/App.js

Notes and comments

The backend is using Express server (server.js) which has a very basic setup with two routes: app.get, app.post.

app.get('/api/get/chat') - for fetching data.json
app.post('/api/post/chat') - for posting new messages (doesn't persist) returns success status(200)

For the client/frontend, I decided to use React, which is inside the '/client' folder.

React can run indepently regardless of the framework or library in the stack. React allows for state management, and with the new React hooks it makes it easier to share states/data in different components without the dreaded prop-drilling.

I structured my folders into components and contexts to keep like-files together.

The chat code starts in app.js and the rest are modularized by components and contexts.

All the data from data.json is fetched in ChatContext which provides the users and posts.

I created an AuthContext to show what it would look like if there was a real authentication. For this app, Auth is faked by hard coding the authentication variables.

Another great reason to use React is it uses ES6, which has a lot of new features. With es6 I can use arrow functions, spread operators, destructuring, promises, all of which can be seen throughout the different js files. All together it creates a more cleaner and more readable code.

React also has jsx templating which makes it easier to integrate html into the react code.

For CSS (index.scss), I am using BEM naming convention as to keep a low specificity on the css selectors. I used SASS for my css preprocessor to allow for css variables, mixins, and nested rules. For the layout I decided to use CSS grid, which initially I used a traditional float and absolute position. However, I thought it would be nice to show some of the newer CSS technologies avaialable.

I made the layout to be mobile-first meaning all default css rules are for mobile, and then media queries for medium to large screen sizes.

As for requirements, I checked off the required specs but I could have added extra features. I wanted to add an initial login page with pre-filled username and password, which then transitions to the main chat page. This would've added a nice user experience.

Author

Marvin Orendain

Version

1.0.0

License

This project is licensed under the MIT License

react_express_chat's People

Contributors

imarvin avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.