We use git to clone the source code. First of all, install git with the following command:
sudo dnf install git

Check successful git installation with command
git version

Clone repository application code
cd ~ec2-user
git clone https://github.com/First-Cloud-Journey/000004-EC2.git

Go to the lab directory 000004-EC2 and check the files
cd 000004-EC2

ls

NPM stands for Node package manager and is a tool to create and manage Javascript programming libraries for Node.js. Using npm init to initialize the project will generate a sample package.json file.
npm init
Note: You proceed to configure the application’s information and it is saved in the file package.json

Next we do dependencies installation
npm install express dotenv express-handlebars body-parser mysql

! How to Fix Vulnerabilities Related to Nodemon
If the number of vulnerabilities is greater than 0 after running npm update and npm audit fix, you can try removing and reinstalling nodemon by following these steps:
npm uninstall nodemon
npm install nodemon@latest --save-dev
npm audit

Explanation:
Check the installed dependencies. The node_modules folder appears.
ls

Create file .env
touch .env

Use vi to edit the .env file. We perform the database configuration:
DB_HOST=localhost
DB_NAME=awsuser
DB_USER=root
DB_PASS=password
Quick Guide to using vi/vim:
Open a file: vi <filename>
Enter insert mode: Press i
Save and exit: Press Esc, then type :wq and press Enter
Quit without saving: Press Esc, then type :q! and press Enter

In the lab we use the database name awsuser and the database information has been configured in the database security configuration step (password: 123Admin)
Check database configuration
ls -a

Start local server
npm start

! Fix TypeError: exphbs is not a function (Express Handlebars)
TypeError: exphbs is not a function
Cause: Newer versions of express-handlebars changed how the module is imported and initialized. The old syntax is no longer supported.
Solution: You can use ‘vi’ or ’nano’ to edit file app.js, replace:
const exphbs = require('express-handlebars'); with:const { engine } = require('express-handlebars');
app.engine('hbs', engine({ extname: '.hbs' })); with:app.engine('hbs', engine({ extname: '.hbs' }));

In the EC2 interface
Paste Public DNS IPv4 address into the browser and port 5000. Observe the AWS FCJ Management interface


In the phpMyAdmin interface, we execute SQL Dummy Data
INSERT INTO `user`
(`id`, `first_name`, `last_name`, `email`, `phone`, `comments`, `status`) VALUES
(NULL, 'Amanda', 'Nunes', 'anunes@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Alexander', 'Volkanovski', 'avolkanovski@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Khabib', 'Nurmagomedov', 'knurmagomedov@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Kamaru', 'Usman', 'kusman@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Israel', 'Adesanya', 'iadesanya@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Henry', 'Cejudo', 'hcejudo@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Valentina', 'Shevchenko', 'vshevchenko@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Tyron', 'Woodley', 'twoodley@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Rose', 'Namajunas ', 'rnamajunas@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Tony', 'Ferguson ', 'tferguson@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Jorge', 'Masvidal ', 'jmasvidal@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Nate', 'Diaz ', 'ndiaz@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Conor', 'McGregor ', 'cmcGregor@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Cris', 'Cyborg ', 'ccyborg@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Tecia', 'Torres ', 'ttorres@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Ronda', 'Rousey ', 'rrousey@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Holly', 'Holm ', 'hholm@ufc.com', '012345 678910', '', 'active'),
(NULL, 'Joanna', 'Jedrzejczyk ', 'jjedrzejczyk@ufc.com', '012345 678910', '', 'active')


Refresh the application interface



Add users

Search for users

Database after inserting the item

The interface of the instance when starting the local server
