Repository for my tutorial on how to set up your first MERN Stack architecture, complete with modern JavaScript trends (MVC, async/await, and modular code).
- (M)ariaDB / (M)ongoDB
- (E)xpress JS
- (R)eact JS
- (N)ode JS
For rapid application development, I use Bootstrap's Dark Theme with standard React.js color theme.
This is an introduction to MERN Stack for people who are unfamiliar with the concept. I use MariaDB as another way to pronounce the "M" word. The reason is because nowadays, it is still a market requirement to use a relational database. Utilizing MongoDB is also possible - and I will make this repository into two versions. One with MariaDB, and the other with MongoDB.
- Axios
- Bootstrap
- CORS
- Dotenv
- Express.js
- MariaDB
- React.js
- Sequelize
- As this is a basic yet powerful tutorial, I will be taking Angular's material: CRUD'ing a Todo app.
- Create a Todo
- Read a Todo
- Update a Todo
- Delete a Todo
- The application was bootstrapped with React.js CRA, and the structure follows it.
- In the
srcfolder, there arecomponents,images, andvariables. Variables are used to store global variable declarations. Components to store the parts of the UI. Images folder is quite self explanatory. - The
backendfolder contains MVC architecture that I use in JavaScript and Express. - There is a simplified differences between ES6 and ES5 JavaScript at the
.changesES6.jsfile. Feel free to take a look at it. It's not essential to the application development, so just delete it if you feel like it.
- First, do
git clone repoto fetch it to your local machine. - Use your command line to
cd repo-path. Make sure to open two command lines, one for the front-end, and one for the back-end. - Change the
backend/.env.examplevariables to any of your webserver setup. Then, rename it to.env. If you have used the initial settings for the backend settings, you should be able to use this application without changing the variables. You just need to rename it to.env. - Create a new database in your web server. Change the variable in the
DB_NAMEto represent your new database. Leave the tables empty. - Finally, use
npm installin the root folder, and also do that command in thebackendfolder to install all the required dependencies. - Run
npm run devin thebackendfolder in order to start the application in the development mode. - Profit!
If you want to deploy this to your web server, you have to do the following:
- In the
package.jsonfile, add a key-value pair namedhomepage: your-homepage-site. - Change the
.env.developmentfile variables. The ones that you have to change are theREACT_APP_DIRECTORY, which is the folder where the application is located. If this application is hosted in root, then leave at it is (/), else change it to your subfolder, aka/react-app-test. After it is done, then rename to.env. - In the
src/components/Header.js, I have already placed theBrowserRouterbasename to be taking from the.envfile. There is no need to manipulate anything, unless you want to change the settings. - After that, run this command:
npm run build. - When the build process is done, you can copy the
buildfolder to your webserver, whether it ishtdocs, yourpublic_html, your subdomain, or you can even create your own server-side setup with Express.js.