-
Installations:
a. Make sure Node.js is installed.
b. Make sure yarn in installed. If not, run the below command after :
npm install -g yarn
c. Make sure MongoDB is installed on your local machine.
-
Make sure the MongoDB database is up and running on the path specified in config.js in the backend-code. To run MongoDB locally, execute the below command in a folder containing a directory named "data" :
mongod --dbpath=data --bind_ip 127.0.0.1
-
Get the back-end's code from the GitHub branch "react-client-integration" and run the Node.js REST API by executing the below command in the NodeBackend directory that will sync from GitHub:
git clone https://github.com/JBakouny/NodeBackend git checkout react-client-integration cd NodeBackend npm install npm start
-
In another folder of your choice, open a new terminal or command line window and clone the front-end code then use yarn to install your dependencies by running the below commands in the folder where you cloned your repo:
git clone https://github.com/JBakouny/React cd React yarn
-
Run the following command to start the web app:
HOST=localhost yarn start
If yarn asks you if it should run on another port, reply with "Y" to have it run on port 3001 instead of port 3000. This conforms with the CORS configurations in the backend's code where the whitelist contains "http://localhost:3001".
To get Google Chrome to accept your self-signed certificate, you should the following: Paste this in your chrome:
chrome://flags/#allow-insecure-localhost
You should see highlighted text saying: Allow invalid certificates for resources loaded from localhost: Click "Enable".
See this stack overflow answer for more info.
The React router enables you to navigate through pages, it also gives you three important props match, location and history as explained here.
Here are some cloud providers that ease the deployment of each of the three parts of full stack application:
-
MongoDB Atlas for the database deployment
-
Heroku for the Node.js/Express back-end which constitutes a REST API
-
The React deployment guide would be useful to chose a server that can deliver your Single Page Application (SPA) front-end. Notably, GitHub Pages is a good free choice if you plan to make your code publicly available. Another option uses Heroku and is also detailed here.
Hooks are not used in this app but the app could be modified to use hooks with functional components instead of classes. More information on hooks are available here.
JavaScript array destruction syntax might also be useful to learn when developping and viewing code related to hooks.
You need to learn hooks to understand some code on the internet like the online explaining how to create React transitions for animations.
This first section is part of the ESIB course, it explains how to create your initial react app with Yarn.
-
Install yarn using globally:
npm install -g yarn
-
Create your initial react app using yarn:
yarn add create-react-app yarn create-react-app confusion
You should commit your
yarn.lock
in git, do not add it to .gitignore -
Make sure the HOST variable in the terminal (or command line) is set to
localhost
.HOST=localhost
Then install the following dependencies:
yarn add bootstrap@4.0.0 yarn add reactstrap@5.0.0 yarn add react-popper@0.9.2
-
Run the below commands to start your application:
yarn start
Your react application can now be consulted on http://localhost:3000/
-
Modify src/App.js and src/index.js in accordance with the Configure React commit.
View the changes by refreshing http://localhost:3000/
PWAs enable the implementation of of Mobile and Web apps that the same code:
- https://create-react-app.dev/docs/making-a-progressive-web-app/
- https://blog.logrocket.com/from-create-react-app-to-pwa/
- https://www.codica.com/blog/how-to-create-pwa-with-react/
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject
at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject
will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject
. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify